added loop

This commit is contained in:
Patryk Koreń
2026-02-12 17:51:08 +01:00
parent f9f0ba9b1f
commit 20a36703e6
4 changed files with 50 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import queue from "./queue"
import resume from "./resume"
import skip from "./skip"
import stop from "./stop"
import loop from "./loop"
export const commands: { [key: string]: Command } = {
ping,
@@ -18,5 +19,6 @@ export const commands: { [key: string]: Command } = {
stop,
pause,
skip,
loop,
}

34
src/commands/loop.ts Normal file
View File

@@ -0,0 +1,34 @@
import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js';
import { toggleLoop } from '../playback';
import { formatFilePath } from '../util/downloader'
const name = "loop"
function register() {
return new SlashCommandBuilder()
.setName(name)
.setDescription('loop current song')
}
async function execute(interaction: ChatInputCommandInteraction<CacheType>) {
try {
await interaction.deferReply()
const audio = toggleLoop()
if (audio) {
await interaction.editReply(`looped ${formatFilePath(audio.url)}`);
}
else {
await interaction.editReply(`Loop turned off`);
}
} catch (error) {
console.error(error);
await interaction.reply('Coś poszło nie tak :/');
}
}
export default {
name,
register,
execute
}