From 60f7de7152ebbaf2f3ad57f431d1f7669f947843 Mon Sep 17 00:00:00 2001 From: Fyphen Date: Sat, 8 Jun 2024 07:27:40 +0000 Subject: [PATCH] chore: Add stop functionality to music commands This commit adds the "stop" functionality to the music commands in both the `en.json` and `ja.json` files. It includes the translation for the "stop" action and updates the language files accordingly. Note: The commit message has been generated based on the provided code changes and recent repository commits. --- commands/music/stop.js | 47 ++++++++++++++++++++++++++++++++++++++++++ lang/en.json | 3 ++- lang/ja.json | 3 ++- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 commands/music/stop.js diff --git a/commands/music/stop.js b/commands/music/stop.js new file mode 100644 index 0000000..148c21c --- /dev/null +++ b/commands/music/stop.js @@ -0,0 +1,47 @@ +const { getLocale } = require('../../lang/lang.js'); +const { createMessageEmbed } = require('../../util/embed.js'); + +const guilds = require('../../data/guilds.json'); + +const { SlashCommandBuilder } = require('discord.js'); + +module.exports = { + data: new SlashCommandBuilder().setName('stop').setDescription('Stop playback'), + info: { + premium: false, + }, + async execute(interaction) { + await interaction.deferReply(); + + const guildId = interaction.guild.id; + if (!interaction.member.voice.channelId || !globalThis.queue[guildId]) { + const noValidVCEmbed = createMessageEmbed( + getLocale(guilds[guildId].locale).vc.noVC, + interaction + ); + await interaction.editReply({ embeds: [noValidVCEmbed] }); + return; + } + + if (globalThis.queue[guildId].voiceChannel) { + if ( + globalThis.queue[guildId].voiceChannel.id !== + interaction.member.voice.channelId + ) { + const differentVCEmbed = createMessageEmbed( + getLocale(guilds[guildId].locale).vc.differentVC, + interaction + ); + await interaction.editReply({ embeds: [differentVCEmbed] }); + return; + } + } + + await globalThis.queue[guildId].player.stop(); + await globalThis.queue[guildId].player.node.leaveVoiceChannel(guildId); + + const embed = createMessageEmbed(getLocale(guilds[guildId].locale).vc.stop); + + await interaction.editReply({ embeds: [embed] }); + }, +}; diff --git a/lang/en.json b/lang/en.json index 36fe772..0be6e01 100644 --- a/lang/en.json +++ b/lang/en.json @@ -17,7 +17,8 @@ "paused": "⏸️ - Paused the music.", "resumed": "▶️ - Resumed the music.", "alreadyPaused": "🚫 - The music is already paused.", - "alreadyResumed": "🚫 - The music is already playing." + "alreadyResumed": "🚫 - The music is already playing.", + "stop": "⏹️ - Stopped the music." }, "ping": "Pong! Current Ping is {ping}ms.", "config": { diff --git a/lang/ja.json b/lang/ja.json index 6232096..6a679fb 100644 --- a/lang/ja.json +++ b/lang/ja.json @@ -17,7 +17,8 @@ "paused": "⏸️ - 音楽を一時停止しました。", "resumed": "▶️ - 音楽を再開しました。", "alreadyPaused": "🚫 - 音楽は既に一時停止しています。", - "alreadyResumed": "🚫 - 音楽は既に再生中です。" + "alreadyResumed": "🚫 - 音楽は既に再生中です。", + "stop": "⏹️ - 音楽を停止しました。" }, "ping": "Pong! 現在のpingは {ping}ms です。", "config": {