mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-01 22:14:59 +00:00
86 lines
3.0 KiB
JavaScript
86 lines
3.0 KiB
JavaScript
const { SlashCommandBuilder } = require('@discordjs/builders');
|
|
const { useQueue } = require('discord-player');
|
|
const { EmbedBuilder } = require('discord.js');
|
|
const { embedColors } = require('../config.json');
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('volume')
|
|
.setDescription('Show or set the playback volume for tracks.')
|
|
.setDMPermission(false)
|
|
.addNumberOption((option) =>
|
|
option
|
|
.setName('percentage')
|
|
.setDescription('Set volume percentage from 1% to 100%.')
|
|
.setMinValue(1)
|
|
.setMaxValue(100)
|
|
),
|
|
run: async ({ interaction }) => {
|
|
if (!interaction.member.voice.channel) {
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setDescription(
|
|
'**Failed**\nYou need to be in a voice channel to use this command.'
|
|
)
|
|
.setColor(embedColors.colorWarning)
|
|
]
|
|
});
|
|
}
|
|
|
|
const queue = useQueue(interaction.guild.id);
|
|
|
|
if (!queue) {
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setDescription(
|
|
'**Failed**\nThere are no tracks playing or in the queue. Add tracks with `/play`!'
|
|
)
|
|
.setColor(embedColors.colorWarning)
|
|
]
|
|
});
|
|
}
|
|
|
|
const volume = interaction.options.getNumber('percentage');
|
|
|
|
if (!volume) {
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setDescription(
|
|
`**Volume**\nThe playback volume is currently set at \`${queue.node.volume}%\`.`
|
|
)
|
|
.setColor(embedColors.colorInfo)
|
|
]
|
|
});
|
|
} else if (volume > 100 || volume < 1) {
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setDescription(
|
|
'**Error**\nYou need to pick a number between `1` and `100`.'
|
|
)
|
|
.setColor(embedColors.colorError)
|
|
]
|
|
});
|
|
} else {
|
|
queue.node.setVolume(volume);
|
|
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setAuthor({
|
|
name: interaction.user.username,
|
|
iconURL: interaction.user.avatarURL()
|
|
})
|
|
.setDescription(
|
|
`**Volume changed**\nPlayback volume has been set to \`${volume}%\`.`
|
|
)
|
|
.setColor(embedColors.colorSuccess)
|
|
]
|
|
});
|
|
}
|
|
}
|
|
};
|