From b07ef030bda866a80b0c4addfbafada2d730b047 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Thu, 6 Jul 2023 10:17:04 +0200 Subject: [PATCH] Added /leave command --- commands/leave.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 commands/leave.js diff --git a/commands/leave.js b/commands/leave.js new file mode 100644 index 0000000..f1322bf --- /dev/null +++ b/commands/leave.js @@ -0,0 +1,52 @@ +const { SlashCommandBuilder } = require('@discordjs/builders'); +const { useMainPlayer, useQueue } = require('discord-player'); +const { EmbedBuilder } = require('discord.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('leave') + .setDescription( + 'Clear the track queue and remove the bot from voice channel.' + ), + run: async ({ interaction }) => { + if (!interaction.member.voice.channel) { + return interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**Error**\nYou need to be in a voice channel to use this command.` + ) + .setColor('#c70057') + ] + }); + } + + const queue = useQueue(interaction.guild.id); + + if (!queue) { + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**Error**\nNo tracks are currently playing, and the queue is empty. Use the \`/play\` command to play some music!` + ) + .setColor('#c70057') + ] + }); + } + + if (!queue.deleted) { + queue.delete(); + + await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**Leaving**\nCleared the track queue and left voice channel. To play more music, use the \`/play\` command!` + ) + .setColor('#4c73df') + ] + }); + } + } +};