0

当我说“+sing”时,我试图让我的机器人加入用户所在的 vc。音频完成后,机器人应断开与 vc 的连接。据我所知,我不知道我做错了什么。

 client.on("message", msg => {
  if (message.content === '+sing') {
    const connection = msg.member.voice.channel.join()
  channel.join().then(connection => {
      console.log("Successfully connected.");
      connection.play(ytdl('https://www.youtube.com/watch?v=jRxSRyrTANY', { quality: 'highestaudio' }));
  }).catch(e => {
      console.error(e);
  connection.disconnect();
  })
});  

顺便说一句,我正在使用 discord.js。

4

1 回答 1

1

您可以获取他们的GuildMember#VoiceState#channel并将其用作加入的频道对象

client.on("message", msg => {
  if (message.content === '+sing') {
    // you should add a check to make sure they are in a voice channel

    // join their channel
    const connection = msg.member.voice.channel.join()
  }
})

于 2021-03-11T09:35:38.990 回答