From 782c3231e19c395c55460a32aaab4c6981ee4f87 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Wed, 5 Jul 2023 15:33:06 +0200 Subject: [PATCH] Added /pause command --- commands/pause.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 commands/pause.js diff --git a/commands/pause.js b/commands/pause.js new file mode 100644 index 0000000..64acbfd --- /dev/null +++ b/commands/pause.js @@ -0,0 +1,56 @@ +const { SlashCommandBuilder } = require('@discordjs/builders'); +const { useMainPlayer, useQueue } = require('discord-player'); +const { EmbedBuilder } = require('discord.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('pause') + .setDescription('Pause the currently playing track.'), + run: async ({ interaction }) => { + if (!interaction.member.voice.channel) { + return interaction.editReply( + 'You need to be in a voice channel to use this command.' + ); + } + + const player = useMainPlayer(); + const queue = useQueue(interaction.guild.id); + + if (!queue) { + return await interaction.editReply( + 'There are no tracks in the queue.' + ); + } + + queue.node.setPaused(!queue.node.isPaused()); + if (queue.node.isPaused()) { + await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setAuthor({ + name: interaction.user.username, + iconURL: interaction.user.avatarURL() + }) + .setDescription( + `**Paused**\n**[${queue.currentTrack.title}](${queue.currentTrack.url})**.` + ) + .setThumbnail(queue.currentTrack.thumbnail) + ] + }); + } else { + await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setAuthor({ + name: interaction.user.username, + iconURL: interaction.user.avatarURL() + }) + .setDescription( + `**Resumed**\n**[${queue.currentTrack.title}](${queue.currentTrack.url})**.` + ) + .setThumbnail(queue.currentTrack.thumbnail) + ] + }); + } + } +};