From 7f1c55e15696988fac2f7ba72dc0dd0f93a97bbf Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Fri, 8 May 2020 15:54:34 +0100 Subject: [PATCH] added pause, resume and skip commands --- commands/music/pause.js | 45 ++++++++++++++++++++++++++++++++++++++++ commands/music/resume.js | 42 +++++++++++++++++++++++++++++++++++++ commands/music/skip.js | 40 +++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 commands/music/pause.js create mode 100644 commands/music/resume.js create mode 100644 commands/music/skip.js diff --git a/commands/music/pause.js b/commands/music/pause.js new file mode 100644 index 0000000..7561aa9 --- /dev/null +++ b/commands/music/pause.js @@ -0,0 +1,45 @@ +const { Command } = require('discord.js-commando'); +const { MessageEmbed } = require('discord.js'); + +module.exports = class Play extends Command { + constructor(client) { + super(client, { + name: 'pause', + memberName: 'pause', + group: 'music', + description: 'pauses the player', + guildOnly: true, + throttling: { + usages: 1, + duration: 5 + } + }); + } + + run = async message => { + try { + if (!message.member.voice.channel) { + const embed = new MessageEmbed().setColor('#ff0000').setTitle(':x: You need to join a voice channel first'); + return await message.say({ embed }); + } + else if (!message.guild.music.isPlaying) { + const embed = new MessageEmbed().setColor('#ff0000').setTitle(':x: Play something first'); + return message.say({ embed }); + } + else if (message.guild.music.paused) { + const embed = new MessageEmbed().setColor('#ff0000').setTitle(':x: Already paused'); + return message.say({ embed }); + } + else { + message.guild.music.paused = true; + message.guild.music.dispatcher.pause(true); + const embed = new MessageEmbed().setColor('#000099').setTitle(':pause_button: paused player'); + return await message.say({ embed }); + } + } catch (err) { + console.error(err); + const embed = new MessageEmbed().setColor('#ff0000').setTitle(':x: Error occured, if you are my creator please fix me soon'); + return message.say({ embed }); + } + } +} \ No newline at end of file diff --git a/commands/music/resume.js b/commands/music/resume.js new file mode 100644 index 0000000..86aece1 --- /dev/null +++ b/commands/music/resume.js @@ -0,0 +1,42 @@ +const { Command } = require('discord.js-commando'); +const { MessageEmbed } = require('discord.js'); + +module.exports = class Play extends Command { + constructor(client) { + super(client, { + name: 'resume', + memberName: 'resume', + group: 'music', + description: 'resumes the player', + guildOnly: true, + throttling: { + usages: 1, + duration: 5 + } + }); + } + + run = async message => { + try { + if (!message.member.voice.channel) return message.reply('you need to join a channel!'); + else if (!message.guild.music.isPlaying) { + const embed = new MessageEmbed().setColor('#ff0000').setTitle(':x: Play something first'); + return message.say({ embed }); + } + else if (!message.guild.music.paused) { + const embed = new MessageEmbed().setColor('#ff0000').setTitle(':x: Playing already'); + return message.say({ embed }); + } + else { + message.guild.music.paused = false; + message.guild.music.dispatcher.resume(); + const embed = new MessageEmbed().setColor('#000099').setTitle(':arrow_forward: resumed player'); + return await message.say({ embed }); + } + } catch (err) { + console.error(err); + const embed = new MessageEmbed().setColor('#ff0000').setTitle(':x: Error occured, if you are my creator please fix me soon'); + return message.say({ embed }); + } + } +} \ No newline at end of file diff --git a/commands/music/skip.js b/commands/music/skip.js new file mode 100644 index 0000000..7325d4d --- /dev/null +++ b/commands/music/skip.js @@ -0,0 +1,40 @@ +const { Command } = require('discord.js-commando'); +const { MessageEmbed } = require('discord.js'); + +module.exports = class Play extends Command { + constructor(client) { + super(client, { + name: 'skip', + memberName: 'skip', + group: 'music', + description: 'skips the current track', + guildOnly: true, + throttling: { + usages: 1, + duration: 5 + } + }); + } + + run = async message => { + try { + if (!message.member.voice.channel) { + const embed = new MessageEmbed().setColor('#ff0000').setTitle(':x: You need to join a voice channel first'); + return await message.say({ embed }); + } + else if (!message.guild.music.isPlaying) { + const embed = new MessageEmbed().setColor('#ff0000').setTitle(':x: Play something first'); + return await message.say({ embed }); + } + else { + message.guild.music.dispatcher.emit('finish'); + const embed = new MessageEmbed().setColor('#000099').setTitle(':stop_button: Skipped current track'); + return await message.say({ embed }); + } + } catch (err) { + console.error(err); + const embed = new MessageEmbed().setColor('#ff0000').setTitle(':x: Error occured, if you are my creator please fix me soon'); + return message.say({ embed }); + } + } +} \ No newline at end of file