【发布时间】:2021-10-06 21:10:41
【问题描述】:
总的来说,我对 discord.js 和 JavaScript 还是很陌生,所以如果这真的很简单,我深表歉意!
我正在开发一个 Discord 机器人,并试图让它为用户指定的语音通道设置一个变量。目前,ChosenChannel 仍然是 null。如果我直接在代码中(第 8 行)将 args 替换为频道名称,它会起作用,但用户无法更改它。
提前感谢您的帮助!
client.on ('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command == 'setchannel') {
//set ChosenChannel to a channel within the current server that matches the name typed by the user (not currently working!)
ChosenChannel = message.guild.channels.cache.find(channel => channel.name === args);
//alert user if ChosenChannel is not an actual channel
if (ChosenChannel == null) {
message.channel.send('Unable to find channel');
//alert user if ChosenChannel is not a voice channel
} else if (ChosenChannel.type !== 'voice') {
message.channel.send('That does not seem to be a voice channel');
//otherwise, confirm that the command worked, and print the name of the channel
} else {
message.channel.send('The chosen channel is: ');
message.channel.send(ChosenChannel.name);
}
}
});
【问题讨论】:
标签: javascript discord discord.js