Skip to content

Commit

Permalink
feat: /stop
Browse files Browse the repository at this point in the history
  • Loading branch information
JirayuSrisawat-Github committed Oct 2, 2024
1 parent e513e18 commit e05b82e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/commands/general/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ms from "ms";
* @since 1.0.0
*/
@ApplyOptions<Command.Options>({
// The description of the command.
description: "Display nodes information",
})
export class UserCommand extends Command {
Expand Down
63 changes: 63 additions & 0 deletions src/commands/music/stop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ApplyOptions } from "@sapphire/decorators";
import { Command } from "@sapphire/framework";
import { Player } from "sakulink";

/**
* The `stop` command.
*
* @since 1.0.0
*/
@ApplyOptions<Command.Options>({
// The description of the command.
description: "Stop playing music.",
})
export class UserCommand extends Command {
/**
* Registers the command to the registry.
*
* @param registry The registry to register the command to.
* @since 1.0.0
*/
public override registerApplicationCommands(registry: Command.Registry): void {
registry.registerChatInputCommand({
name: this.name,
description: this.description,
});
}

/**
* Runs the command when it is invoked.
*
* @param interaction The interaction that invoked the command.
* @since 1.0.0
*/
public override async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
// Get the player for the guild
const player: Player | undefined = this.container.client.manager.get(interaction.guildId!);
if (!player) {
// If the player is not found, return an error message
return await interaction.reply({
embeds: [
{
color: 0xff0000,
description: "No music is being played.",
},
],
});
}

// Stop the player
player.destroy();

// Reply with a success message
await interaction.reply({
embeds: [
{
color: 0xeab676,
description: "Stopped playing music.",
},
],
});
}
}

0 comments on commit e05b82e

Please sign in to comment.