【发布时间】: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