mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 06:28:53 +00:00
Retrieve main player and guild queue in command
This commit is contained in:
1 parent
5c27855559
commit
761807ebe4
2 files changed
+22
-7
No files matched your search
+18
-2
@@ -1,5 +1,7 @@
|
||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { useMainPlayer, useQueue } = require('discord-player');
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('play')
|
||||
@@ -10,14 +12,16 @@ module.exports = {
|
||||
.setDescription('Search terms or URL.')
|
||||
.setRequired(true)
|
||||
),
|
||||
run: async ({ interaction, player }) => {
|
||||
run: async ({ interaction }) => {
|
||||
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('query');
|
||||
const player = useMainPlayer();
|
||||
const queue = useQueue(interaction.guild.id);
|
||||
const query = interaction.options.getString('query');
|
||||
|
||||
try {
|
||||
const { track } = await player.play(
|
||||
@@ -45,6 +49,18 @@ module.exports = {
|
||||
)
|
||||
.setThumbnail(track.thumbnail)
|
||||
]
|
||||
/* can add this to /queue command to skip tracks?
|
||||
,
|
||||
components: [
|
||||
new ActionRowBuilder().addComponents([
|
||||
new ButtonBuilder()
|
||||
.setCustomId('skip')
|
||||
.setLabel('Skip track')
|
||||
.setStyle('Secondary')
|
||||
.setEmoji('⏭️')
|
||||
])
|
||||
]
|
||||
*/
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(`Error occured while trying to play track:\n\n${e}`);
|
||||
|
||||
@@ -66,7 +66,7 @@ client.on('interactionCreate', async (interaction) => {
|
||||
|
||||
try {
|
||||
await interaction.deferReply();
|
||||
await command.run({ interaction, player });
|
||||
await command.run({ interaction });
|
||||
console.log(
|
||||
`Command '/${interaction.commandName}' was executed successfully.`
|
||||
);
|
||||
@@ -76,10 +76,9 @@ client.on('interactionCreate', async (interaction) => {
|
||||
`Command '/${interaction.commandName}' failed unexpectedly.`
|
||||
);
|
||||
|
||||
await interaction.editReply({
|
||||
content: 'There was an error while executing this command!',
|
||||
ephemeral: true
|
||||
});
|
||||
await interaction.editReply(
|
||||
'There was an error while executing this command!'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user