|
| 1 | +import { ApplicationCommandOptionType, EmbedBuilder } from "discord.js"; |
| 2 | +import { Manager } from "../../manager.js"; |
| 3 | +import { Accessableby, Command } from "../../structures/Command.js"; |
| 4 | +import { CommandHandler } from "../../structures/CommandHandler.js"; |
| 5 | +import { RainlinkPlayer } from "../../rainlink/main.js"; |
| 6 | + |
| 7 | +// Main code |
| 8 | +export default class implements Command { |
| 9 | + public name = ["skipto"]; |
| 10 | + public description = "Skip to a specific position"; |
| 11 | + public category = "Music"; |
| 12 | + public accessableby = Accessableby.Member; |
| 13 | + public usage = ""; |
| 14 | + public aliases = ["sk"]; |
| 15 | + public lavalink = true; |
| 16 | + public options = [ |
| 17 | + { |
| 18 | + name: "position", |
| 19 | + description: "The position of the song", |
| 20 | + type: ApplicationCommandOptionType.Number, |
| 21 | + required: true, |
| 22 | + }, |
| 23 | + ]; |
| 24 | + public playerCheck = true; |
| 25 | + public usingInteraction = true; |
| 26 | + public sameVoiceCheck = true; |
| 27 | + public permissions = []; |
| 28 | + |
| 29 | + public async execute(client: Manager, handler: CommandHandler) { |
| 30 | + await handler.deferReply(); |
| 31 | + const player = client.rainlink.players.get(handler.guild!.id) as RainlinkPlayer; |
| 32 | + |
| 33 | + const getPosition = Number(handler.args[0]); |
| 34 | + |
| 35 | + if (!handler.args[0] || isNaN(getPosition) || getPosition < 0) |
| 36 | + return handler.editReply({ |
| 37 | + embeds: [ |
| 38 | + new EmbedBuilder() |
| 39 | + .setDescription(`${client.getString(handler.language, "error", "number_invalid")}`) |
| 40 | + .setColor(client.color), |
| 41 | + ], |
| 42 | + }); |
| 43 | + |
| 44 | + if (player.queue.size == 0 || getPosition >= player.queue.length) { |
| 45 | + const skipped = new EmbedBuilder() |
| 46 | + .setDescription(`${client.getString(handler.language, "command.music", "skip_notfound")}`) |
| 47 | + .setColor(client.color); |
| 48 | + |
| 49 | + handler.editReply({ content: " ", embeds: [skipped] }); |
| 50 | + } else { |
| 51 | + const cuttedQueue = player.queue.splice(0, getPosition); |
| 52 | + const nowCurrentTrack = cuttedQueue.splice(-1)[0]; |
| 53 | + player.queue.previous.push(...cuttedQueue); |
| 54 | + player.queue.current ? player.queue.previous.unshift(player.queue.current) : true; |
| 55 | + await player.play(nowCurrentTrack); |
| 56 | + player.queue.shift(); |
| 57 | + const skipped = new EmbedBuilder() |
| 58 | + .setDescription(`${client.getString(handler.language, "command.music", "skip_msg")}`) |
| 59 | + .setColor(client.color); |
| 60 | + handler.editReply({ content: " ", embeds: [skipped] }); |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments