【问题标题】:How do I prevent my terminal from stopping when my discord bot is in a VC当我的不和谐机器人在 VC 中时,如何防止我的终端停止
【发布时间】:2021-06-15 16:43:00
【问题描述】:

我最近使用 discord.js 制作了一个不和谐机器人。我创建的机器人加入了 VC 并播放音乐。有时,当机器人尝试加入 VC 时,我的终端会崩溃。如何阻止这种情况发生并使其继续使用代码。

这是我到目前为止所得到的。

client.on('message', async message => {
  if (message.member.voice.channel) {
    const connection = await message.member.voice.channel.join();
    connection.play(ytdl('https://www.youtube.com/watch?v=jRxSRyrTANY', { quality: 'highestaudio' },{ type: 'opus' }));
    setTimeout(() => {
    connection.disconnect();
  }, 12000); 
if (console.log.error);
  }
});

另外,这个网站 (https://discordjs.guide/voice/optimisation-and-troubleshooting.html#preparing-your-bot-for-debugging) 建议这样做

client.on('debug', console.log);

channel.join().then(connection => {
    connection.on('debug', console.log);
});

但我不知道把它放在代码的什么地方? 我该怎么办?

【问题讨论】:

  • bot 崩溃时出现什么错误?

标签: debugging discord discord.js bots voice


【解决方案1】:

要回答您的部分问题,

但我不知道把它放在代码的什么地方?我该怎么办?

您可以将代码粘贴到client.on('message') 事件下。
Here 是一份不和谐事件的备忘单,以了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-18
    • 2020-11-10
    • 2021-11-24
    • 2020-06-30
    • 2019-11-15
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多