当我的不和谐机器人在 VC 中时,如何防止我的终端停止

问题描述

我最近刚刚使用 discord.js 制作了一个 discord 机器人。我创建的机器人加入了 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);
});

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

解决方法

要回答您的部分问题,

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

您可以将代码粘贴到 Resources r = mContext.getResources(); int px = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP,yourdpmeasure,r.getDisplayMetrics() ); 事件下。
Here 是一份不和谐事件备忘单,供您了解更多信息。