From ac5f65844d61f516253b8ebb43a051be426a3429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Kore=C5=84?= Date: Mon, 29 Dec 2025 18:14:59 +0100 Subject: [PATCH] added skip --- src/commands/index.ts | 2 ++ src/commands/skip.ts | 27 +++++++++++++++++++++++++++ src/playback.ts | 13 +++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/commands/skip.ts diff --git a/src/commands/index.ts b/src/commands/index.ts index 9ef53bd..369e604 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -5,6 +5,7 @@ import ping from "./ping" import play from "./play" import queue from "./queue" import resume from "./resume" +import skip from "./skip" import stop from "./stop" export const commands: { [key: string]: Command } = { @@ -16,5 +17,6 @@ export const commands: { [key: string]: Command } = { resume, stop, pause, + skip, } diff --git a/src/commands/skip.ts b/src/commands/skip.ts new file mode 100644 index 0000000..a7db12b --- /dev/null +++ b/src/commands/skip.ts @@ -0,0 +1,27 @@ +import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; +import { skip_song } from '../playback'; + +const name = "skip" + +function register() { + return new SlashCommandBuilder() + .setName(name) + .setDescription('skip song') +} + +async function execute(interaction: ChatInputCommandInteraction) { + try { + await interaction.deferReply() + skip_song() + await interaction.editReply('skipped'); + } catch (error) { + console.error(error); + await interaction.reply('Coś poszło nie tak :/'); + } +} + +export default { + name, + register, + execute +} diff --git a/src/playback.ts b/src/playback.ts index f63c027..7df85f0 100644 --- a/src/playback.ts +++ b/src/playback.ts @@ -42,6 +42,19 @@ export async function updatePlayer() { } } +export function skip_song() { + if (player.state.status === AudioPlayerStatus.Playing) { + const nextSong = queue.songList.shift() + if (!nextSong) { + queue.current = null + player.stop() + return + }; + queue.current = nextSong; + playSong(player, nextSong); + } +} + export function pause_playback(player: AudioPlayer) { player.pause() }