diff options
author | TymanWasTaken <tyman@tyman.tech> | 2021-05-16 22:03:18 -0400 |
---|---|---|
committer | TymanWasTaken <tyman@tyman.tech> | 2021-05-16 22:03:18 -0400 |
commit | 759e93bec4e9e2eb86db7434007345c24b0a0252 (patch) | |
tree | 193c47e5dfc6bcce0f4923ea0d2f8f7ce2e5894a /src/commands/admin | |
parent | 284e1d1d693486f6c50cdb8b38f01cdf74eb63d2 (diff) | |
download | tanzanite-759e93bec4e9e2eb86db7434007345c24b0a0252.tar.gz tanzanite-759e93bec4e9e2eb86db7434007345c24b0a0252.tar.bz2 tanzanite-759e93bec4e9e2eb86db7434007345c24b0a0252.zip |
fix logging for slash command syncing v2, delete BotMessage and BotGuild because useless, add prefix slash command
Diffstat (limited to 'src/commands/admin')
-rw-r--r-- | src/commands/admin/prefix.ts | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/src/commands/admin/prefix.ts b/src/commands/admin/prefix.ts index 3948a7e..32af649 100644 --- a/src/commands/admin/prefix.ts +++ b/src/commands/admin/prefix.ts @@ -1,5 +1,7 @@ +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction, Message } from 'discord.js'; import { BotCommand } from '../../lib/extensions/BotCommand'; -import { BotMessage } from '../../lib/extensions/BotMessage'; +import { Guild } from '../../lib/models'; export default class PrefixCommand extends BotCommand { constructor() { @@ -16,21 +18,50 @@ export default class PrefixCommand extends BotCommand { 'Set the prefix of the current server (resets to default if prefix is not given)', usage: 'prefix [prefix]', examples: ['prefix', 'prefix +'] - } + }, + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.STRING, + name: 'prefix', + description: 'The prefix to set for this server', + required: false + } + ] }); } - async exec( - message: BotMessage, - { prefix }: { prefix?: string } - ): Promise<void> { + async exec(message: Message, { prefix }: { prefix?: string }): Promise<void> { if (prefix) { - await message.settings.setPrefix(prefix); + const row = await Guild.findByPk(message.guild.id); + row.prefix = prefix; + await row.save(); await message.util.send(`Sucessfully set prefix to \`${prefix}\``); } else { - await message.settings.setPrefix(this.client.config.prefix); + const row = await Guild.findByPk(message.guild.id); + row.prefix = this.client.config.prefix; + await row.save(); await message.util.send( `Sucessfully reset prefix to \`${this.client.config.prefix}\`` ); } } + + async execSlash(message: CommandInteraction): Promise<void> { + const prefix = message.options.find((o) => o.name === 'prefix')?.value as + | string + | undefined; + + if (prefix) { + const row = await Guild.findByPk(message.guild.id); + row.prefix = prefix; + await row.save(); + await message.reply(`Sucessfully set prefix to \`${prefix}\``); + } else { + const row = await Guild.findByPk(message.guild.id); + row.prefix = this.client.config.prefix; + await row.save(); + await message.reply( + `Sucessfully reset prefix to \`${this.client.config.prefix}\`` + ); + } + } } |