aboutsummaryrefslogtreecommitdiff
path: root/src/commands/admin/prefix.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/admin/prefix.ts')
-rw-r--r--src/commands/admin/prefix.ts47
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}\``
+ );
+ }
+ }
}