require('dotenv').config(); const { SlashCommandBuilder, EmbedBuilder } = require("discord.js"); module.exports = { category: 'music', data: new SlashCommandBuilder() .setName('play') .setDescription('Play XenoFM.'), async execute(interaction, client) { if (!interaction.member.voice.channel) return interaction.reply({ content: "Please join a VC" }); let player = client.moon.players.create({ guildId: interaction.guild.id, voiceChannel: interaction.member.voice.channel.id, textChannel: interaction.channel.id, autoPlay: true, }); if (!player.connected) { player.connect({ setDeaf: true, setMute: false, }); } let res = await client.moon.search('music-link-here'); if (res.loadType === "loadfailed") { // Respond with an error message if loading fails return interaction.reply({ content: `:x: Load failed. `, }); } else if (res.loadType === "empty") { // Respond with a message if the search returns no results return interaction.reply({ content: `:x: No matches!`, }); } if (res.loadType === 'playlist') { interaction.reply({ content: `${res.playlistInfo.name} this playlist has been added to the waiting list`, }); for (const track of res.tracks) { // Add tracks to the queue if it's a playlist player.queue.add(track); } } else { player.queue.add(res.tracks[0]); interaction.reply({ content: `${res.tracks[0].title} was added to the waiting list`, }); } if (!player.playing) { // Start playing if it's not already playing player.play(); } } }