From 4f0db62170398c542d23fcee3812f0887901f977 Mon Sep 17 00:00:00 2001 From: Thongrapee Panyapatiphan Date: Fri, 25 Feb 2022 06:24:45 +0700 Subject: Add stop command (#540) Co-authored-by: Max Isom --- src/commands/stop.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/commands/stop.ts (limited to 'src/commands') diff --git a/src/commands/stop.ts b/src/commands/stop.ts new file mode 100644 index 0000000..3c32c7f --- /dev/null +++ b/src/commands/stop.ts @@ -0,0 +1,37 @@ +import {CommandInteraction} from 'discord.js'; +import {SlashCommandBuilder} from '@discordjs/builders'; +import {TYPES} from '../types.js'; +import {inject, injectable} from 'inversify'; +import PlayerManager from '../managers/player.js'; +import {STATUS} from '../services/player.js'; +import Command from '.'; + +@injectable() +export default class implements Command { + public readonly slashCommand = new SlashCommandBuilder() + .setName('stop') + .setDescription('stop playback, disconnect, and clear all songs in the queue'); + + public requiresVC = true; + + private readonly playerManager: PlayerManager; + + constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) { + this.playerManager = playerManager; + } + + public async execute(interaction: CommandInteraction) { + const player = this.playerManager.get(interaction.guild!.id); + + if (!player.voiceConnection) { + throw new Error('not connected'); + } + + if (player.status !== STATUS.PLAYING) { + throw new Error('not currently playing'); + } + + player.stop(); + await interaction.reply('u betcha'); + } +} -- cgit v1.2.3