Retrieve main player and guild queue in command

This commit is contained in:
Marius Begby committed 2023-07-05 15:32:29 +02:00
1 parent 5c27855559
commit 761807ebe4
2 files changed
+22 -7

No files matched your search

+18 -2
View File
@@ -1,5 +1,7 @@
const { SlashCommandBuilder } = require('@discordjs/builders'); const { SlashCommandBuilder } = require('@discordjs/builders');
const { useMainPlayer, useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js'); const { EmbedBuilder } = require('discord.js');
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('play') .setName('play')
@@ -10,14 +12,16 @@ module.exports = {
.setDescription('Search terms or URL.') .setDescription('Search terms or URL.')
.setRequired(true) .setRequired(true)
), ),
run: async ({ interaction, player }) => { run: async ({ interaction }) => {
if (!interaction.member.voice.channel) { if (!interaction.member.voice.channel) {
return interaction.editReply( return interaction.editReply(
'You need to be in a voice channel to use this command.' '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 { try {
const { track } = await player.play( const { track } = await player.play(
@@ -45,6 +49,18 @@ module.exports = {
) )
.setThumbnail(track.thumbnail) .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) { } catch (e) {
console.log(`Error occured while trying to play track:\n\n${e}`); console.log(`Error occured while trying to play track:\n\n${e}`);
+4 -5
View File
@@ -66,7 +66,7 @@ client.on('interactionCreate', async (interaction) => {
try { try {
await interaction.deferReply(); await interaction.deferReply();
await command.run({ interaction, player }); await command.run({ interaction });
console.log( console.log(
`Command '/${interaction.commandName}' was executed successfully.` `Command '/${interaction.commandName}' was executed successfully.`
); );
@@ -76,10 +76,9 @@ client.on('interactionCreate', async (interaction) => {
`Command '/${interaction.commandName}' failed unexpectedly.` `Command '/${interaction.commandName}' failed unexpectedly.`
); );
await interaction.editReply({ await interaction.editReply(
content: 'There was an error while executing this command!', 'There was an error while executing this command!'
ephemeral: true );
});
} }
}); });