I am trying to do the simple task of playing a single MP3 file when a command is run. The file is stored locally, and I have FFmpeg installed on my computer. The code below is part of my command's file:
const Discord = require("discord.js");
const fs = require('fs');
const { Client, RichEmbed } = require('discord.js');
const config = require("../config.json");
let playing = undefined;
let connection = undefined;
module.exports.run = async (client, message, args, config) => {
if (playing) playing.end()
if (connection == undefined) await message.member.voice.channel.join().then((c) => {
connection = c;
})
playing = connection.play('./sounds/sound.mp3')
}
(note that this code is heavily narrowed down to single out the issue)
When I run the command the first 9 times, it works perfectly - the file is played, and cuts off if it is already playing. I also want to note that the file is ~2 minutes long. However, once I play the file for exactly the 10th time, the bot stops playing audio entirely - as long as all 10 times are overlapping (meaning I don't let the audio finish).
What's more confusing is that if an error is passed after the bot stops playing audio, it appears in an entirely different format than the standard Discord.js errors. For example, this code does not test to see if the user is in a voice channel, so if I purposefully crash the bot by initiating the command without being in a voice channel (after running the command 10 times), the error looks like this:
abort(RangeError: offset is out of bounds). Build with -s ASSERTIONS=1 for more info.
(Use `electron --trace-uncaught ...` to show where the exception was thrown)
(Preceded by a bunch of unformatted code) This however, is not consistent. It seems to only appear after letting the files run entirely.
The issue only fixes itself when the entire bot restarts. Any help would be appreciated.