From 33102d64dc50b92af8881769d5db4bf9c1d37d61 Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Sun, 29 Sep 2024 15:39:49 +0900 Subject: [PATCH] feat: slash command for help command --- package.json | 2 +- src/Client.ts | 2 +- src/Commands/help.ts | 45 +++++++++++++++++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 2b1c14f..f4c7488 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "muffinbot", - "version": "4.0.0-pudding.experimental_slash_test.2", + "version": "4.0.0-pudding.experimental_slash_test.3", "main": "dist/index.js", "private": true, "dependencies": { diff --git a/src/Client.ts b/src/Client.ts index 80c9289..562966b 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -22,7 +22,7 @@ container.version = version container.database = new PrismaClient() container.dokdoAliases = ['dokdo', 'dok', 'Dokdo', 'Dok', '테스트'] container.chatBot = new ChatBot(container.database) -container.lastUpdated = new Date('2024-09-28') +container.lastUpdated = new Date('2024-09-29') if (release.startsWith('e')) { container.channel = 'EXPERIMENTAL' diff --git a/src/Commands/help.ts b/src/Commands/help.ts index ea228a6..9ac7e35 100644 --- a/src/Commands/help.ts +++ b/src/Commands/help.ts @@ -1,6 +1,10 @@ import { Args, Command, container } from '@sapphire/framework' -import { codeBlock, type Message } from 'discord.js' import { ApplyOptions } from '@sapphire/decorators' +import { + type ChatInputCommandInteraction, + codeBlock, + Message, +} from 'discord.js' @ApplyOptions({ name: '도움말', @@ -12,8 +16,32 @@ import { ApplyOptions } from '@sapphire/decorators' }, }) class HelpCommand extends Command { - public async messageRun(msg: Message, args: Args) { - const commandName = await args.pick('string').catch(() => null) + public registerApplicationCommands(registry: Command.Registry) { + const commands = this.container.stores.get('commands').map(command => { + return { + name: command.name, + value: command.name, + } + }) + registry.registerChatInputCommand(builder => + builder + .setName(this.name) + .setDescription(this.description) + .addStringOption(option => + option + .setName('명령어') + .setDescription('해당 명령어에 대ㅎ한 도움말을 볼 수 있어요.') + .addChoices(commands), + ), + ) + } + private async _run(ctx: Message | ChatInputCommandInteraction, args?: Args) { + let commandName: string | null + if (ctx instanceof Message) { + commandName = await args!.pick('string').catch(() => null) + } else { + commandName = ctx.options.getString('명령어') + } if ( !commandName || !this.container.stores.get('commands').get(commandName) @@ -24,7 +52,7 @@ class HelpCommand extends Command { commandList.push(`${module.name} - ${module.description}`) }) - await msg.reply({ + await ctx.reply({ embeds: [ { title: `${this.container.client.user?.username}의 도움말`, @@ -44,7 +72,7 @@ class HelpCommand extends Command { this.container.stores.get('commands').get(commandName)! if (typeof detailedDescription === 'string') return - await msg.reply({ + await ctx.reply({ embeds: [ { title: `${this.container.client.user?.username}의 도움말`, @@ -86,6 +114,13 @@ class HelpCommand extends Command { }) } } + public async messageRun(msg: Message, args: Args) { + await this._run(msg, args) + } + + public async chatInputRun(interaction: ChatInputCommandInteraction) { + await this._run(interaction) + } } void container.stores.loadPiece({