mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 22:15:29 +00:00
Added /play command to play a track
This commit is contained in:
1 parent
2e60abde52
commit
26ae2871d3
1 file changed
+54
@@ -0,0 +1,54 @@
|
|||||||
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
|
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 ({ client, interaction, player }) => {
|
||||||
|
if (!interaction.member.voice.channel) {
|
||||||
|
return interaction.editReply(
|
||||||
|
'You need to be in a voice channel to use this command.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let query = interaction.options.getString('track');
|
||||||
|
|
||||||
|
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)
|
||||||
|
]
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`Error occured while trying to play track:\n\n${e}`);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in new issue
Block a user