【问题标题】:discord.js Check if user and bot are in the same voice channeldiscord.js 检查用户和机器人是否在同一个语音通道中
【发布时间】:2021-05-01 06:59:59
【问题描述】:

我实际上在过去 30 分钟内没有找到任何有效的方法。

当有人执行命令时,我希望我的音乐机器人检查它是否在语音频道中,以及机器人和用户是否在同一个频道中。

这是我最近的尝试:

if (
  bot.voiceConnections.get(
    bot.guilds.get(message.guild.id).id.channel.id !== 'undefined',
  ) &&
  bot.voiceConnections.get(message.guild.id).channel.id !==
    message.member.voice.channel.id
)
  return message.channel.send(
    '>>> :x: | You need to be in channel together with me.',
  );

【问题讨论】:

  • 您介意将代码放在代码块中吗?
  • 对不起,我放错了```。

标签: discord.js


【解决方案1】:

您可以检查用户是否有语音状态以及该语音状态是否与您在同一频道中

if (message.member.voice && guild.voice && message.member.voice.channelID === guild.voice.channelID) {
 // whatever next
};

了解更多信息:
GuildMember voice
Guild Voice

【讨论】:

    猜你喜欢
    • 2021-08-18
    • 2020-09-09
    • 2021-07-04
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 2021-04-13
    • 1970-01-01
    • 2021-07-28
    相关资源
    最近更新 更多