diff --git a/commands/Sound/playsound.js b/commands/Sound/playsound.js index a2d40ed..a78417a 100644 --- a/commands/Sound/playsound.js +++ b/commands/Sound/playsound.js @@ -12,7 +12,7 @@ module.exports = { displayHelp: false, }, - run: async (bot, message, args) => { + run: async (bot, message, args, callback) => { if (message.member.voice.channel) { let soundPath = __dirname + `/../../sounds/` const connection = await message.member.voice.channel.join() @@ -25,6 +25,7 @@ module.exports = { dispatcher.on('finish', () => { connection.voice.channel.leave() + callback() }) } else { message.reply('How can I scare your companions without you beeing present in the voice channel?') diff --git a/events/message.js b/events/message.js index c8eef78..f0496a2 100644 --- a/events/message.js +++ b/events/message.js @@ -3,6 +3,24 @@ const { prefix, colors } = require('../config.json') const reactMessage = require('../utils/reactMessage') +cmdQueue = [] +handlingCommand = false + +var waitToRunCommand = function() { + setTimeout(runCommand, 300) +} + +var runCommand = function() { + handlingCommand = true + const cmdFunc = cmdQueue.shift() + cmdFunc.cmd.run(cmdFunc.bot, cmdFunc.message, cmdFunc.args, done) +} + +var done = function() { + handlingCommand = false + if (cmdQueue.length > 0) waitToRunCommand() +} + module.exports = async (bot, webhook, message) => { if (message.author.bot) return // Ignore all bots if (message.author.id === bot.user.id) return // Ignore bot itself @@ -40,10 +58,13 @@ module.exports = async (bot, webhook, message) => { }) return } - cmd.run(bot, message, args) // Run the command + // ----- Push to queue and wait for other jobs to finish ----- + cmdQueue.push({cmd: cmd, bot: bot, message: message, args: args}) + if (!handlingCommand) { + waitToRunCommand() + } } else { // -------------------- Reaction system -------------------- - // console.log(reactMessage) reactMessage(message.guild.id, message) } }