From da8fc8a4902d1069de9ab141bd126c986da3fe36 Mon Sep 17 00:00:00 2001 From: zebz213 Date: Fri, 15 Mar 2024 01:09:08 -0400 Subject: [PATCH] Create PlayNext Command Add's command that add's a song/playlist next in queue. Signed-off-by: zebz213 --- src/commands/music/PlayNext.ts | 168 +++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 src/commands/music/PlayNext.ts diff --git a/src/commands/music/PlayNext.ts b/src/commands/music/PlayNext.ts new file mode 100644 index 000000000..b827ac7fd --- /dev/null +++ b/src/commands/music/PlayNext.ts @@ -0,0 +1,168 @@ +import { LoadType } from 'shoukaku'; + +import { Command, Context, Lavamusic } from '../../structures/index.js'; + +export default class PlayNext extends Command { + constructor(client: Lavamusic) { + super(client, { + name: 'playnext', + description: { + content: 'Add the song to play next in queue', + examples: [ + 'playnext https://www.youtube.com/watch?v=QH2-TGUlwu4', + 'playnext https://open.spotify.com/track/6WrI0LAC5M1Rw2MnX2ZvEg', + ], + usage: 'playnext ', + }, + category: 'music', + aliases: ['pn'], + cooldown: 3, + args: true, + player: { + voice: true, + dj: false, + active: false, + djPerm: null, + }, + permissions: { + dev: false, + client: ['SendMessages', 'ViewChannel', 'EmbedLinks', 'Connect', 'Speak'], + user: [], + }, + slashCommand: true, + options: [ + { + name: 'song', + description: 'The song you want to play', + type: 3, + required: true, + autocomplete: true, + }, + ], + }); + } + public async run(client: Lavamusic, ctx: Context, args: string[]): Promise { + const query = args.join(' '); + let player = client.queue.get(ctx.guild.id); + const vc = ctx.member as any; + if (!player) player = await client.queue.create(ctx.guild, vc.voice.channel, ctx.channel); + + const res = await this.client.queue.search(query); + const embed = this.client.embed(); + switch (res.loadType) { + case LoadType.ERROR: + ctx.sendMessage({ + embeds: [ + embed + .setColor(this.client.color.red) + .setDescription('There was an error while searching.'), + ], + }); + break; + case LoadType.EMPTY: + ctx.sendMessage({ + embeds: [ + embed + .setColor(this.client.color.red) + .setDescription('There were no results found.'), + ], + }); + break; + case LoadType.TRACK: { + const track = player.buildTrack(res.data, ctx.author); + if (player.queue.length > client.config.maxQueueSize) + return await ctx.sendMessage({ + embeds: [ + embed + .setColor(this.client.color.red) + .setDescription( + `The queue is too long. The maximum length is ${client.config.maxQueueSize} songs.` + ), + ], + }); + player.queue.splice(0, 0, track); + await player.isPlaying(); + ctx.sendMessage({ + embeds: [ + embed + .setColor(this.client.color.main) + .setDescription( + `Added [${res.data.info.title}](${res.data.info.uri}) to play next in the queue.` + ), + ], + }); + break; + } + case LoadType.PLAYLIST: { + if (res.data.tracks.length > client.config.maxPlaylistSize) + return await ctx.sendMessage({ + embeds: [ + embed + .setColor(this.client.color.red) + .setDescription( + `The playlist is too long. The maximum length is ${client.config.maxPlaylistSize} songs.` + ), + ], + }); + for (const track of res.data.tracks) { + const pl = player.buildTrack(track, ctx.author); + if (player.queue.length > client.config.maxQueueSize) + return await ctx.sendMessage({ + embeds: [ + embed + .setColor(this.client.color.red) + .setDescription( + `The queue is too long. The maximum length is ${client.config.maxQueueSize} songs.` + ), + ], + }); + player.queue.splice(0, 0, pl); + } + await player.isPlaying(); + ctx.sendMessage({ + embeds: [ + embed + .setColor(this.client.color.main) + .setDescription(`Added ${res.data.tracks.length} songs to play next in the queue.`), + ], + }); + break; + } + case LoadType.SEARCH: { + const track1 = player.buildTrack(res.data[0], ctx.author); + if (player.queue.length > client.config.maxQueueSize) + return await ctx.sendMessage({ + embeds: [ + embed + .setColor(this.client.color.red) + .setDescription( + `The queue is too long. The maximum length is ${client.config.maxQueueSize} songs.` + ), + ], + }); + player.queue.splice(0, 0, track1); + await player.isPlaying(); + ctx.sendMessage({ + embeds: [ + embed + .setColor(this.client.color.main) + .setDescription( + `Added [${res.data[0].info.title}](${res.data[0].info.uri}) to play next in the queue.` + ), + ], + }); + break; + } + } + } +} + +/** + * Project: lavamusic + * Author: Blacky + * Company: Coders + * Copyright (c) 2023. All rights reserved. + * This code is the property of Coder and may not be reproduced or + * modified without permission. For more information, contact us at + * https://discord.gg/ns8CTk9J3e + */