Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
831 views
in Technique[技术] by (71.8m points)

discord.js - Issues with audio and playing in more than one server

async function play(message, correct, channel, mp3) {
  const connection = await channel.join();
  await new Promise(done => setTimeout(done, 1000));
  let readStream = await fs.createReadStream(mp3);
  await timerEventEmitter.emit("update", correct);
  const dispatcher = await connection.play(readStream)
      .on('end', () => {
          console.log('Stream ended!');
      })
      .on('finish', () => {
          console.log('Stream finished!');
      })
      .on('error', error => {
          console.error(error);
      });
  timerEventEmitter.on('end', (time) => {
      dispatcher.destroy();
  })
}

This might be a big or small issue, I hope it's the latter but it's most likely the former. My bot is supposed to play audio in a voice chat and it works perfectly fine in one server.

However, when I try playing audio at the same time in two different servers, the audio does some weird stuff. The audio cuts out and ends in one server while playing the other audio in the other server.

Below is the code from above that I use to play the audio. I'm not really getting an error but I do need maybe an explanation or a solution if I want to add this bot to multiple servers. I'm sure there's a good explanation; hopefully it doesn't require a rework.

Also, it's not a bad connection issue either as I tried it on localhost and replit, and they both had that same issue.

let readStream = await fs.createReadStream(mp3);

const dispatcher = await connection.play(readStream);
question from:https://stackoverflow.com/questions/65912531/discord-js-issues-with-audio-and-playing-in-more-than-one-server

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...