feat: slash command for help command
This commit is contained in:
parent
355fd0b1f3
commit
33102d64dc
3 changed files with 42 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "muffinbot",
|
"name": "muffinbot",
|
||||||
"version": "4.0.0-pudding.experimental_slash_test.2",
|
"version": "4.0.0-pudding.experimental_slash_test.3",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -22,7 +22,7 @@ container.version = version
|
||||||
container.database = new PrismaClient()
|
container.database = new PrismaClient()
|
||||||
container.dokdoAliases = ['dokdo', 'dok', 'Dokdo', 'Dok', '테스트']
|
container.dokdoAliases = ['dokdo', 'dok', 'Dokdo', 'Dok', '테스트']
|
||||||
container.chatBot = new ChatBot(container.database)
|
container.chatBot = new ChatBot(container.database)
|
||||||
container.lastUpdated = new Date('2024-09-28')
|
container.lastUpdated = new Date('2024-09-29')
|
||||||
|
|
||||||
if (release.startsWith('e')) {
|
if (release.startsWith('e')) {
|
||||||
container.channel = 'EXPERIMENTAL'
|
container.channel = 'EXPERIMENTAL'
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import { Args, Command, container } from '@sapphire/framework'
|
import { Args, Command, container } from '@sapphire/framework'
|
||||||
import { codeBlock, type Message } from 'discord.js'
|
|
||||||
import { ApplyOptions } from '@sapphire/decorators'
|
import { ApplyOptions } from '@sapphire/decorators'
|
||||||
|
import {
|
||||||
|
type ChatInputCommandInteraction,
|
||||||
|
codeBlock,
|
||||||
|
Message,
|
||||||
|
} from 'discord.js'
|
||||||
|
|
||||||
@ApplyOptions<Command.Options>({
|
@ApplyOptions<Command.Options>({
|
||||||
name: '도움말',
|
name: '도움말',
|
||||||
|
@ -12,8 +16,32 @@ import { ApplyOptions } from '@sapphire/decorators'
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
class HelpCommand extends Command {
|
class HelpCommand extends Command {
|
||||||
public async messageRun(msg: Message, args: Args) {
|
public registerApplicationCommands(registry: Command.Registry) {
|
||||||
const commandName = await args.pick('string').catch(() => null)
|
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 (
|
if (
|
||||||
!commandName ||
|
!commandName ||
|
||||||
!this.container.stores.get('commands').get(commandName)
|
!this.container.stores.get('commands').get(commandName)
|
||||||
|
@ -24,7 +52,7 @@ class HelpCommand extends Command {
|
||||||
commandList.push(`${module.name} - ${module.description}`)
|
commandList.push(`${module.name} - ${module.description}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
await msg.reply({
|
await ctx.reply({
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
title: `${this.container.client.user?.username}의 도움말`,
|
title: `${this.container.client.user?.username}의 도움말`,
|
||||||
|
@ -44,7 +72,7 @@ class HelpCommand extends Command {
|
||||||
this.container.stores.get('commands').get(commandName)!
|
this.container.stores.get('commands').get(commandName)!
|
||||||
if (typeof detailedDescription === 'string') return
|
if (typeof detailedDescription === 'string') return
|
||||||
|
|
||||||
await msg.reply({
|
await ctx.reply({
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
title: `${this.container.client.user?.username}의 도움말`,
|
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({
|
void container.stores.loadPiece({
|
||||||
|
|
Loading…
Reference in a new issue