歌曲结束后,Discord音乐机器人不会离开服务器

时间:2020-08-01 09:38:31

标签: javascript arrays discord discord.js

我正在开发一个名为Amadeus的不和谐机器人。当Amadeus收到指定命令时,他会播放音乐...嗯...他会的。现在,当我仍在为他工作时,他只播放一首歌。当他连接到语音频道并完美播放自己的歌曲时-他的歌曲结束后就不会离开语音频道。由于某种原因,我想它永远也检测不到歌曲结束了吗?任何帮助表示赞赏

const connection = message.member.voice.channel.name;
const channel = message.member.voice.channel;
message.channel.send("Now playing Scythe OST in the " + connection + " channel.");
channel.join().then(connection => {
    const dispatcher = connection.play('./Scythe Digital Edition - Soundtrack/01 Europa 1920.mp3');
    dispatcher.on("end", end => {
      channel.leave()
    });
  })
  .catch(console.error);

1 个答案:

答案 0 :(得分:0)

按照@Tenclea的建议,如果您查看Discord.js Documentation > Topics,就会发现使用了dispatcher.on("finish", () => {})

const channel = message.member.voice.channel;
message.channel.send(`Now playing Scythe OST in the ${channel.name} channel.`);
channel.join().then(connection => {
    const dispatcher = connection.play("./Scythe Digital Edition - Soundtrack/01 Europa 1920.mp3");
    dispatcher.on("finish", () => channel.leave());
}).catch(e => console.log(e))

dispatcher.on("end", () => {})将在Discord JS版本11上运行。