mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-02 14:38:49 +00:00
66 lines
2.3 KiB
JavaScript
66 lines
2.3 KiB
JavaScript
const { SlashCommandBuilder } = require('@discordjs/builders');
|
|
const { useMainPlayer, useQueue } = require('discord-player');
|
|
const { EmbedBuilder } = require('discord.js');
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('play')
|
|
.setDescription('Play a track provided by search terms or URL.')
|
|
.addStringOption((option) =>
|
|
option
|
|
.setName('query')
|
|
.setDescription('Search terms or URL.')
|
|
.setRequired(true)
|
|
),
|
|
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 player = useMainPlayer();
|
|
const queue = useQueue(interaction.guild.id);
|
|
const query = interaction.options.getString('query');
|
|
|
|
try {
|
|
const { track } = await player.play(
|
|
interaction.member.voice.channel,
|
|
query,
|
|
{
|
|
requestedBy: interaction.user,
|
|
nodeOptions: {
|
|
leaveOnEmptyCooldown: 60000,
|
|
leaveOnEndCooldown: 60000,
|
|
leaveOnStopCooldown: 60000
|
|
}
|
|
}
|
|
);
|
|
|
|
await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setAuthor({
|
|
name: interaction.user.username,
|
|
iconURL: interaction.user.avatarURL()
|
|
})
|
|
.setDescription(
|
|
`**Added to queue**\n\`[${track.duration}]\` **[${track.title}](${track.url})**`
|
|
)
|
|
.setThumbnail(track.thumbnail)
|
|
.setColor('#4c73df')
|
|
]
|
|
});
|
|
} catch (e) {
|
|
console.log(`Error occured while trying to play track:\n\n${e}`);
|
|
throw e;
|
|
}
|
|
}
|
|
};
|