【问题标题】:Why does the Discord bot not see the user?为什么 Discord 机器人看不到用户?
【发布时间】:2020-09-27 18:05:18
【问题描述】:

使用命令时,机器人必须连接到语音通道,但为了连接,它必须看到在此语音通道中使用命令调用它的用户。但是,这不会发生,机器人返回否定结果,它看不到用户。有什么问题?

代码:

const queue = new Map();

async function execute(message, serverQueue) {
 const args = message.content.split(' ');
 const voiceChannel = message.member.voiceChannel;
 if (!voiceChannel) return message.channel.send('You need to be in a voice channel to play music!');
  const permissions = voiceChannel.permissionsFor(message.client.user);
 if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) {
  return message.channel.send('I need the permissions to join and speak in your voice channel!');
 }
}

【问题讨论】:

  • 你使用的是什么版本的 discord.js?
  • 哦,我在哪里可以查看?
  • 检查你的package.json文件
  • discord.js@12.2.0

标签: javascript discord.js


【解决方案1】:

由于 discord.js v12 你需要使用voice.channel 而不是voiceChannel

const queue = new Map();

async function execute(message, serverQueue) {
 const args = message.content.split(' ');
 const voiceChannel = message.member.voice.channel;
 if (!voiceChannel) return message.channel.send('You need to be in a voice channel to play music!');
  const permissions = voiceChannel.permissionsFor(message.client.user);
 if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) {
  return message.channel.send('I need the permissions to join and speak in your voice channel!');
 }
}

【讨论】:

  • 谢谢,现在连接好了。
猜你喜欢
  • 2021-12-12
  • 1970-01-01
  • 2020-12-16
  • 2018-08-17
  • 2021-09-16
  • 2021-08-13
  • 1970-01-01
  • 2019-02-19
  • 2021-01-21
相关资源
最近更新 更多