From ae5f8799a8401768627208fcfebbb001ec02596b Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 5 Feb 2023 01:01:30 +0100 Subject: [PATCH] add stop command --- src/commands/music/stop.ts | 41 ++++++++++++++++++++++++++++++++++++++ src/locales/fr.json | 6 +++++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/commands/music/stop.ts diff --git a/src/commands/music/stop.ts b/src/commands/music/stop.ts new file mode 100644 index 0000000..b58771a --- /dev/null +++ b/src/commands/music/stop.ts @@ -0,0 +1,41 @@ +import { SlashCommandBuilder } from "@discordjs/builders"; +import { ChatInputCommandInteraction, Client, GuildResolvable } from "discord.js"; +import { Metadata } from "../../modules/metadata"; +import { getLocale, getLocalizations } from "../../utils/locales"; +import { getFilename } from "../../utils/misc"; + +export default { + scope: () => [], + + data: (client: Client) => { + const filename = getFilename(__filename); + const loc_default = client.locales.get(client.config.default_lang); + if (!loc_default) { + return; + } + + return new SlashCommandBuilder() + .setName(filename.toLowerCase()) + .setDescription(loc_default.get(`c_${filename}_desc`) ?? "") + .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)); + }, + + interaction: async (interaction: ChatInputCommandInteraction, client: Client) => { + const loc = getLocale(client, interaction.locale); + + const queue = client.player.createQueue(interaction.guild as GuildResolvable, { + metadata: { + channel: interaction.channel, + } as Metadata, + }); + + if (!(queue.connection || queue.playing)) { + return interaction.reply(loc.get("c_stop1")); + } + + queue.destroy(); + + interaction.reply(loc.get("c_stop2")); + }, +}; diff --git a/src/locales/fr.json b/src/locales/fr.json index 52a18ad..56e457d 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -81,5 +81,9 @@ "c_play_name": "play", "c_play_desc": "Joue une chanson/playlist", "c_play_opt1_name": "requête", - "c_play_opt1_desc": "Ce que vous voulez écouter" + "c_play_opt1_desc": "Ce que vous voulez écouter", + "c_stop_name": "stop", + "c_stop_desc": "Stop la musique", + "c_stop1": "Le bot ne joue pas de musique.", + "c_stop2": "La musique à été arrêtée." }