【问题标题】:Discord js / Check if user is in an specific voice ChannelDiscord js /检查用户是否在特定的语音频道中
【发布时间】:2021-05-03 18:11:58
【问题描述】:

我希望我的机器人使用“

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 频道中!

任何想法为什么这样做?

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    问题是

    if (voiceChannelID === '789186504483536937', '791444742042943548')
    

    这不是多个条件的工作方式。用 or 运算符分隔。

    if (voiceChannelID === '789186504483536937' || voiceChannelID === '791444742042943548')
    

    您可以将您尝试做的事情想象为传入两个不同的条件 f(x, y)。 Javascript 中的 if 语句只会检查最后一个 (y),并且“791444742042943548”是真的,因为它是非空的。

    【讨论】:

    • 谢谢!我实际上试过 if (voiceChannelID === '789186504483536937' || '791444742042943548') 之前...:D
    • if (voiceChannelID === '789186504483536937' || '791444742042943548'),永远是真的。您需要添加第二个voiceChannelID ===(如答案所示)。或使用if (['789186504483536937', '791444742042943548'].includes(voiceChannelID))
    猜你喜欢
    • 2021-03-30
    • 2021-05-07
    • 2021-04-13
    • 1970-01-01
    • 2020-06-26
    • 2021-12-13
    • 2017-11-05
    • 2021-09-08
    • 2022-07-10
    相关资源
    最近更新 更多