diff --git a/commands/play.js b/commands/play.js index 33f1a08..2b6801d 100644 --- a/commands/play.js +++ b/commands/play.js @@ -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}`); diff --git a/index.js b/index.js index 7304d1c..a8543c9 100644 --- a/index.js +++ b/index.js @@ -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!' + ); } });