diff --git a/src/commands/player/leave.js b/src/commands/player/leave.js index 26e4414..db0860b 100644 --- a/src/commands/player/leave.js +++ b/src/commands/player/leave.js @@ -38,20 +38,20 @@ module.exports = { logger.debug( `[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and deleted the queue.` ); - - return await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setAuthor({ - name: interaction.member.nickname || interaction.user.username, - iconURL: interaction.user.avatarURL() - }) - .setDescription( - `**${embedOptions.icons.success} Leaving channel**\nCleared the track queue and left voice channel.\n\nTo play more music, use the **\`/play\`** command!` - ) - .setColor(embedOptions.colors.success) - ] - }); } + + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setAuthor({ + name: interaction.member.nickname || interaction.user.username, + iconURL: interaction.user.avatarURL() + }) + .setDescription( + `**${embedOptions.icons.success} Leaving channel**\nCleared the track queue and left voice channel.\n\nTo play more music, use the **\`/play\`** command!` + ) + .setColor(embedOptions.colors.success) + ] + }); } }; diff --git a/src/commands/player/play.js b/src/commands/player/play.js index 861c0b2..53378cf 100644 --- a/src/commands/player/play.js +++ b/src/commands/player/play.js @@ -78,11 +78,11 @@ module.exports = { requestedBy: interaction.user, nodeOptions: { leaveOnEmpty: playerOptions.leaveOnEmpty ?? true, - leaveOnEmptyCooldown: playerOptions.leaveOnEmptyCooldown ?? 60000, + leaveOnEmptyCooldown: playerOptions.leaveOnEmptyCooldown ?? 300_000, leaveOnEnd: playerOptions.leaveOnEnd ?? true, - leaveOnEndCooldown: playerOptions.leaveOnEndCooldown ?? 60000, + leaveOnEndCooldown: playerOptions.leaveOnEndCooldown ?? 300_000, leaveOnStop: playerOptions.leaveOnStop ?? true, - leaveOnStopCooldown: playerOptions.leaveOnStopCooldown ?? 60000, + leaveOnStopCooldown: playerOptions.leaveOnStopCooldown ?? 300_000, maxSize: playerOptions.maxQueueSize ?? 1000, maxHistorySize: playerOptions.maxHistorySize ?? 100, volume: playerOptions.defaultVolume ?? 50, diff --git a/src/commands/player/stop.js b/src/commands/player/stop.js new file mode 100644 index 0000000..6423a98 --- /dev/null +++ b/src/commands/player/stop.js @@ -0,0 +1,58 @@ +const logger = require('../../services/logger'); +const { embedOptions } = require('../../config'); +const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); +const { useQueue } = require('discord-player'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('stop') + .setDescription('Stop playing audio and clear the track queue.') + .setDMPermission(false), + + // todo, allow command to be executed if bot is only member in voice channel + execute: async ({ interaction }) => { + if (await notInVoiceChannel(interaction)) { + return; + } + + const queue = useQueue(interaction.guild.id); + + if (!queue) { + logger.debug( + `[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no queue.` + ); + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**${embedOptions.icons.warning} Oops!**\n_Hmm.._ It seems I am not in a voice channel!` + ) + .setColor(embedOptions.colors.warning) + ] + }); + } + + if (!queue.deleted) { + queue.clear(); + queue.node.stop(); + logger.debug( + `[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and cleared the queue.` + ); + } + + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setAuthor({ + name: interaction.member.nickname || interaction.user.username, + iconURL: interaction.user.avatarURL() + }) + .setDescription( + `**${embedOptions.icons.success} Stopped playing**\nStopped playing audio and cleared the track queue.\n\nTo play more music, use the **\`/play\`** command!` + ) + .setColor(embedOptions.colors.success) + ] + }); + } +}; diff --git a/src/config_example.js b/src/config_example.js index 0693f32..46584c5 100644 --- a/src/config_example.js +++ b/src/config_example.js @@ -102,11 +102,11 @@ module.exports.embedOptions = { // Options for the discord-player player. module.exports.playerOptions = { leaveOnEmpty: true, - leaveOnEmptyCooldown: 300000, + leaveOnEmptyCooldown: 300_000, leaveOnEnd: true, - leaveOnEndCooldown: 300000, + leaveOnEndCooldown: 300_000, leaveOnStop: true, - leaveOnStopCooldown: 300000, + leaveOnStopCooldown: 300_000, defaultVolume: 50, maxQueueSize: 1000, maxHistorySize: 100,