mbot/commands/music/play.js
2024-07-04 02:14:01 -07:00

42 lines
1.4 KiB
JavaScript

const { SlashCommandBuilder, PermissionsBitField } = require('discord.js');
const { useMainPlayer } = require('discord-player');
const informationStatus = "[INFO]: ";
const warningStatus = "[WARNING]: ";
const errorStatus = "[ERROR]: ";
module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Plays a video through a link!')
.addStringOption(option =>
option
.setName('link')
.setDescription('The link to play the music.')
.setRequired(true)),
async execute(interaction) {
const player = useMainPlayer();
const channel = interaction.member.voice.channel;
if(!channel) return interaction.reply({ content: "You are not connected to a voice channel.", ephemeral: true });
const query = interaction.options.getString('link', true);
await interaction.deferReply();
try {
const { track } = await player.play(channel, query, {
nodeOptions: {
metadata: interaction
}
});
console.log(`${informationStatus}Playing ${track.title} from ${track.author} in ${interaction.guildId}`);
return interaction.followUp(`<:checkmark:1238964552482422844> **${track.title}** from **${track.author}** has been added to the queued!`);
} catch (error) {
await interaction.followUp({content: "Something went wrong! Please try again later.", ephemeral: true });
return console.log(error);
}
}
}