From 02ff34a1f47a00420e55922b7a63589fe26764be Mon Sep 17 00:00:00 2001 From: zebz213 Date: Thu, 14 Mar 2024 23:56:41 -0400 Subject: [PATCH] Create PlayNext command New command to add a song 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..1db7bb05d --- /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 Play 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 + */