問題描述
我希望我的機器人通過使用<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:
您已經在 AFK 頻道中!
You are already in an AFK channel!
任何想法為什么這樣做?
Any ideas why it does this?
推薦答案
問題是
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".是真實的,因為它是非空的.
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/檢查用戶是否在特定的語音頻道中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!