diff options
author | TymanWasTaken <32660892+tymanwastaken@users.noreply.github.com> | 2021-05-07 13:16:46 -0600 |
---|---|---|
committer | TymanWasTaken <32660892+tymanwastaken@users.noreply.github.com> | 2021-05-07 13:16:46 -0600 |
commit | d4d5d0e822c9570a2ca9ef86cc21073dbbec2087 (patch) | |
tree | 417c66368a79820b0ac2f36cd051e71b22b96f87 /src/listeners/client | |
parent | 6c0cfa0857e98889dcc676364f66e184e0250098 (diff) | |
download | tanzanite-d4d5d0e822c9570a2ca9ef86cc21073dbbec2087.tar.gz tanzanite-d4d5d0e822c9570a2ca9ef86cc21073dbbec2087.tar.bz2 tanzanite-d4d5d0e822c9570a2ca9ef86cc21073dbbec2087.zip |
slash commands working and added execSlash to ping command
Diffstat (limited to 'src/listeners/client')
-rw-r--r-- | src/listeners/client/CreateSlashCommands.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/listeners/client/CreateSlashCommands.ts b/src/listeners/client/CreateSlashCommands.ts new file mode 100644 index 0000000..f747f4a --- /dev/null +++ b/src/listeners/client/CreateSlashCommands.ts @@ -0,0 +1,48 @@ +import { BotListener } from '../../lib/extensions/BotListener'; + +export default class CreateSlashCommands extends BotListener { + constructor() { + super('createslashcommands', { + emitter: 'client', + event: 'ready' + }); + } + async exec(): Promise<void> { + try { + const enabled = await this.client.application.commands.fetch(); + for (const command of enabled) { + if (!this.client.commandHandler.modules.find((cmd) => cmd.id == command[1].name)) { + await this.client.application.commands.delete(command[1].id); + console.log('deleted', command[1].name); + } + } + + for (const cmd of this.client.commandHandler.modules) { + if (cmd[1].execSlash) { + const found = enabled.find((i) => i.name == cmd[1].id); + + const slashdata = { + name: cmd[1].id, + description: cmd[1].description.content, + options: cmd[1].options.slashCommandOptions + }; + + if (found?.id) { + if (slashdata.description !== found.description) { + await this.client.application.commands.edit(found.id, slashdata); + } + } else { + console.log('enabled', cmd[1].id); + await this.client.application.commands.create(slashdata); + } + } + } + + + return console.log('Slash commands registered'); + } catch (e) { + console.log(e); + return console.log('Slash commands not registered, see above error.'); + } + } +} |