From 49003aa33a30c623af55992f8155866818eb6dc2 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Mon, 1 Mar 2021 22:43:51 -0500 Subject: [PATCH] Fix Pokemon cries being playable in middle of other commands --- commands/pokedex/pokedex-cry.js | 6 +++++- commands/pokedex/pokedex.js | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/commands/pokedex/pokedex-cry.js b/commands/pokedex/pokedex-cry.js index 3c90edc2..a306386b 100644 --- a/commands/pokedex/pokedex-cry.js +++ b/commands/pokedex/pokedex-cry.js @@ -61,8 +61,12 @@ module.exports = class PokedexCryCommand extends Command { const usage = this.client.registry.commands.get('join').usage(); return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`); } + if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.'); try { - connection.play(pokemon.cry); + const dispatcher = connection.play(pokemon.cry); + this.client.dispatchers.set(msg.guild.id, dispatcher); + dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id)); + dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id)); await reactIfAble(msg, this.client.user, '🔉'); return null; } catch (err) { diff --git a/commands/pokedex/pokedex.js b/commands/pokedex/pokedex.js index c2e2db37..aa404c80 100644 --- a/commands/pokedex/pokedex.js +++ b/commands/pokedex/pokedex.js @@ -112,10 +112,13 @@ module.exports = class PokedexCommand extends Command { .addField('❯ Gender Rate', pokemon.genderRate.genderless ? 'Genderless' : `♂️ ${pokemon.genderRate.male}% ♀️ ${pokemon.genderRate.female}%`); - if (pokemon.cry) { + if (pokemon.cry && !this.client.dispatchers.has(msg.guild.id)) { const connection = msg.guild ? this.client.voice.connections.get(msg.guild.id) : null; if (connection) { - connection.play(pokemon.cry); + const dispatcher = connection.play(pokemon.cry); + this.client.dispatchers.set(msg.guild.id, dispatcher); + dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id)); + dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id)); await reactIfAble(msg, this.client.user, '🔉'); } }