const { CommandInteraction, MessageEmbed, Client } = require("discord.js"); const config = require("../../Structures/config.json"); module.exports = { name: "music", description: "Complete music system", options: [ { name: "play", description: "Play a song.", type: "SUB_COMMAND", options: [ { name: "query", description: "Provide name or url for music.", type: "STRING", required: true, }, ], }, { name: "volume", description: "Volume control.", type: "SUB_COMMAND", options: [ { name: "percent", description: "10 - 100%", type: "NUMBER", required: true, }, ], }, { name: "seek", description: "Volume control.", type: "SUB_COMMAND", options: [ { name: "seconds", description: "How much seconds", type: "NUMBER", required: true, }, ], }, { name: "settings", description: "Select an option.", type: "SUB_COMMAND", options: [ { name: "options", description: "Select option", type: "STRING", required: true, choices: [ { name: "📃 Music Queue", value: "queue" }, { name: "⏸ Pause Music", value: "pause" }, { name: "▶ Resume Music", value: "resume" }, { name: "⏭ Skip Music", value: "skip" }, { name: "⏹ Stop Music", value: "stop" }, { name: "⏹ Shuffle Music", value: "shuffle" }, { name: "🔃 Toggle Autoplay Modes", value: "AutoPlay" }, { name: "🔄 Add a Related Song", value: "RelatedSong" }, { name: "🔁 Toggle Repeat Mode", value: "RepeatMode" }, ], }, ], }, ], /** * * @param {CommandInteraction} ineraction * @param {Client} bot */ async execute(ineraction, bot) { const { options, member, guild, channel } = ineraction; const voice_channel = member.voice.channel; if (!voice_channel) { return ineraction.reply({ content: "`You must join voice channel to use the command`", ephemeral: true, }); } if ( guild.me.voice.channelId && voice_channel.id !== guild.me.voice.channelId ) { return ineraction.reply({ content: `\`I am already playing music in <#${guild.me.voice.channelId}>\``, ephemeral: true, }); } try { switch (options.getSubcommand()) { case "play": { bot.distube.play(voice_channel, options.getString("query"), { textChannel: channel, member: member, }); return ineraction.reply({ content: "`Request accepted.`" }); } case "volume": { const volume = options.getNumber("percent"); if (volume > 100 || volume < 1) { return ineraction.reply({ content: "`You have to specify a number between 1 and 100`", ephemeral: true, }); } bot.distube.setVolume(voice_channel, volume); return ineraction.reply({ content: `\`Volume has set to ${volume}%\``, }); } case "seek": { const seconds = options.getNumber("seconds"); let duration = bot.distube.getQueue(ineraction).songs[0].duration; // console.log(seconds); // console.log(duration); if (seconds > duration || seconds < 0) { return ineraction.reply({ content: `\`Seconds must between the duration 0 to ${duration}\``, ephemeral: true, }); } await bot.distube.seek(ineraction, seconds); return ineraction.reply({ content: `\`Song has seeked to ${seconds}s of ${duration}s\``, }); } case "settings": { const queue = await bot.distube.getQueue(voice_channel); if (!queue) { return ineraction.reply({ content: "`There is no Queue`", }); } switch (options.getString("options")) { case "skip": await queue.skip(voice_channel); return ineraction.reply({ content: "`⏭ Music has been skipped.`", }); case "stop": await queue.stop(voice_channel); return ineraction.reply({ content: "`⏺ Music has been stopped.`", }); case "pause": await queue.pause(voice_channel); return ineraction.reply({ content: "`⏸ Music has been paused.`", }); case "resume": await queue.resume(voice_channel); return ineraction.reply({ content: "`▶ Music has been resumed.`", }); case "shuffle": await queue.shuffle(voice_channel); return ineraction.reply({ content: "`⏹ Music has been shuffled.`", }); case "AutoPlay": let mode = await queue.toggleAutoplay(voice_channel); return ineraction.reply({ content: `\`🔃 AutoPlay Mode set to ${mode ? "ON" : "OFF"}\``, }); case "RelatedSong": await queue.addRelatedSong(voice_channel); return ineraction.reply({ content: "`🔄 A related song has added.`", }); case "RepeatMode": let mode_2 = await bot.distube.setRepeatMode(queue); return ineraction.reply({ content: `\`🔁 RepeatMode Mode set to ${(mode_2 = mode_2 ? mode_2 == 2 ? "Queue" : "Song" : "Off")}\``, }); case "queue": return ineraction.reply({ embeds: [ new MessageEmbed() .setColor("#FF6600") .setDescription( `🎶 ${queue.songs.map( (song, id) => `\n**${id + 1}**. ${song.name} - \`${ song.formattedDuration }\`` )}` ), ], }); } return; } } } catch (error) { const errEmbed = new MessageEmbed() .setColor(config.COLOR_RED) .setDescription(`Alert: ${error.toString()}`); return ineraction.reply({ embeds: [errEmbed], ephemeral: true }); } }, };