【问题标题】:Discord make channel bot that requires confirmationDiscord制作需要确认的频道机器人
【发布时间】:2020-08-25 04:42:22
【问题描述】:

我希望下面的命令!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);

【问题讨论】:

  • 你是如何获得那些所谓的公会和频道令牌的?
  • 它们是在启用开发者选项后从 discord 应用中复制而来的
  • 我将实际的令牌编号更改为这些词,因此我没有发布私人信息。真实代码使用来自 discord 应用程序的令牌编号。
  • 它们不被称为令牌,它们被称为 ID,隐藏 ID 并不重要,因为除非有人在具有该 ID 的公会/频道中(使用机器人或只是他们自己的用户) ,他们找不到 ID 的任何用处
  • 你使用的是什么版本的 discord.js?

标签: javascript node.js discord discord.js


【解决方案1】:

这个问题已经有了答案。链接在这里: How to create a text channel 我希望它足以解决您的问题。

【讨论】:

  • @noam Cohen 除非您有实际答案,而不仅仅是重定向到另一个答案,不要发布答案,只需使用 cmets。
  • @Syntle 我不行,我的声望不够
猜你喜欢
  • 2023-03-14
  • 2017-09-16
  • 2017-06-18
  • 2020-07-16
  • 2021-04-24
  • 2020-01-16
  • 1970-01-01
  • 1970-01-01
  • 2020-11-23
相关资源
最近更新 更多