Discord js/检查用户是否在特定的语音频道中

Discord js / Check if user is in an specific voice Channel(Discord js/检查用户是否在特定的语音频道中)
本文介绍了Discord js/检查用户是否在特定的语音频道中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我希望我的机器人通过使用<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/检查用户是否在特定的语音频道中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Auto-reply to direct messages(自动回复直接消息)
Play local music files using djs v13(使用 djs v13 播放本地音乐文件)
Making a bot delete its own message after a timeout(让机器人在超时后删除自己的消息)
How do I upload a custom emoji to my discord bot(如何将自定义表情符号上传到我的不和谐机器人)
Discord.js meme command with meme subreddit returns image as 403 forbidden(带有 meme subreddit 的 Discord.js meme 命令将图像返回为 403 禁止)
How to get snekfetch results into an object?(如何将 snekfetch 结果放入对象中?)