#How to handle multiple AudioPlayers' error?

13 messages · Page 1 of 1 (latest)

weary gust
#

So I have an array of JSON with guild specific audio players, queue, etc. I was wondering could I handle the errors that come from the audio players.

// index.js
bot.queue = {};

// some command that plays specific music
if (!inter.client.queue[inter.guild.id]) {
  inter.client.queue[inter.guild.id] = {
    // Whatever
  }
}
fading kite
#

I‘m confused, AudioPlayer‘s are class instances, how can they be stored as JSON?

weary gust
#
if (!bot.queue[inter.guild.id]) {
            bot.queue[inter.guild.id] = {
                player: createAudioPlayer(),
                source: createAudioResource(stream, { inlineVolume: true }),
                queue: [], 
                volume: 1.0,
                loop: loop,
                channel: inter.member.voice.channel.id
            }
fading kite
#

So not JSON but JS objects, understood

weary gust
#

yeah

#

right after this i start making a connection and subscribe to the player

fading kite
#

Attach handlers to the error event of the player then

weary gust
#

i know you could do ```js
bot.queue[guild.id].player.on('error', error => {
console.log(error.message);
});

but how would you get the id that the player is erroring on
fading kite
#

For example ```js
bot.queue[guild.id].player.on('error', error => {
console.log([${guild.id}] => ${error.message});
});

weary gust
#

that's not what I meant i meant the id in the []

fading kite
#

Me too

weary gust
#

bot.queue[guild.id]