需要确认的D​​iscord Make渠道漫游器

时间:2020-05-09 15:31:14

标签: javascript node.js discord discord.js

我希望以下命令!addclass nameofclass向管理频道发送一条消息,询问我们是否要将该类添加为频道,监听!yes!no,以及是否!yes创建该频道。我不确定guild.channels.create应该如何正确使用。我认为我必须定义channels,但我不知道该定义什么。

guild.channels.create({name: newclassname})
               ^    
TypeError: Cannot read property 'create' of undefined
const Discord = require('discord.js');
const Client = new Discord.Client();

const token = 'bottoken';

const guild = 'guildToken';

const PREFIX = '!';

Client.on('ready', () => {
    console.log('This Client is online!');
})

const adminchannel = Client.channels.cache.get('adminchanneltoken')

Client.on('message', message => {

    let args = message.content.substring(PREFIX.length).split(" ");

    switch (args[0]) {
        case 'addclass':
            const newclassname = args[1];
            if (message.channel.id != 'addclasschanneltoken') {

                Client.channels.cache.get('adminchanneltoken').send('someone wants to add "' + newclassname + '" as a class name')
                Client.channels.cache.get('adminchanneltoken').send('do you want to add it? (yes or no)')

                if (message.channel.id != 'adminchanneltoken') {

                    Client.on('message', message => {

                        let argsrespond = message.content.substring(PREFIX.length).split(" ");

                        switch (argsrespond[0]) {
                            case 'yes':
                                Client.guilds.cache.get('guildToken');
                                Client.channels.cache.get('guildToken');
                                guild.channels.create({
                                        name: newclassname
                                    })
                                    .then(console.log)
                                    .catch(console.error);
                                break;
                            case 'no':
                                break;
                        }
                    })
                } else {}
            } else {}
    }
})

Client.login(token);

1 个答案:

答案 0 :(得分:0)

该问题已经有了答案。链接在这里: How to create a text channel 我希望它能很好地回答您的问题。