首页 > 解决方案 > Discord.js 语音机器人在播放本地 mp3 文件时中断

问题描述

我的机器人播放 mp3 声音,但在接近尾声时会中断,尤其是对于短 (<2s) 文件。

多次重装ffmpeg

client.on('message', message => {
  // Voice only works in guilds, if the message does not come from a guild,
  // we ignore it
  if (!message.guild) return;

    if (message.content === '!sound') {
    // Only try to join the sender's voice channel if they are in one themselves
    if (message.member.voiceChannel) {
      message.member.voiceChannel.join()
        .then(connection => { // Connection is an instance of VoiceConnection
          const dispatcher = connection.playFile('C:/Users/X/Desktop/my-bot/Sounds/SJW2.mp3');

          dispatcher.on("end", end => {connection.disconnect});
        })
        .catch(console.log);
        client.on('end', () => {
  // The song has finished
});

没有错误,声音只是在文件末尾附近被删掉。

标签: node.jsdiscorddiscord.jsvoice

解决方案


尝试使用作品的声音。此外,您的主机的互联网速度会影响它。这可能是由于高延迟


推荐阅读