问题描述
我希望我的机器人通过使用< afk [radio]"和"afk [radio]"在2个afk频道中的1个中移动用户.命令.但是我首先要检查用户是否已经在AFK频道中.我试过了:
I want my bot to move a user in 1 of 2 afk channels by using a "<afk [radio]" command.But i first want to check if the user is allready in an AFK Channel. I tried:
const voiceChannel = message.member.voice.channel;
const voiceChannelID = message.member.voice.channelID;
if (!voiceChannel) {
return message.channel.send('You are not in an voice Channel so why move to AFK?');
} else if (voiceChannelID === '789186504483536937', '791444742042943548') {
return message.channel.send('You are already in an AFK channel!');
} else if (!args.length) {
return member.voice.setChannel('789186504483536937');
}
但是当我尝试不使用< afk"时,命令机器人发送消息:
But when i try t use the "<afk" command the bot send the message:
为什么要这么做?
推荐答案
问题是
if (voiceChannelID === '789186504483536937', '791444742042943548')
这不是多个条件的工作方式.用or运算符将其分隔.
This is not how multiple conditionals work. Seperate it with the or operator.
if (voiceChannelID === '789186504483536937' || voiceChannelID === '791444742042943548')
您可以考虑在两个不同的条件f(x,y)中传递时要尝试做的事情.如果Javascript中的if语句仅检查最后一个(y),则"791444742042943548"是真的,因为它不是null.
You can think of what you were trying to do as passing in two different conditions, f(x, y). If statements in Javascript will only check for the last one (y), and "791444742042943548" is truthy since it is non-null.
这篇关于Discord js/检查用户是否在特定的语音通道中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!