aboutsummaryrefslogtreecommitdiff
path: root/src/commands/config/prefix.ts
blob: 9c1ce92b1b9d012606bb6aba160247bdae745cc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage } from '@lib';

export default class PrefixCommand extends BushCommand {
	public constructor() {
		super('prefix', {
			aliases: ['prefix'],
			category: 'config',
			description: {
				content: 'Set or reset the prefix for the server.',
				usage: 'prefix [prefix]',
				examples: ['prefix', 'prefix -']
			},
			args: [
				{
					id: 'prefix',
					type: 'string',
					prompt: {
						start: 'What would you like the new prefix to be?',
						retry: '{error} Choose a valid prefix',
						optional: true
					}
				}
			],
			slash: true,
			slashOptions: [
				{
					name: 'prefix',
					description: 'What would you like the new prefix to be?',
					type: 'STRING',
					required: false
				}
			],
			channel: 'guild',
			clientPermissions: ['SEND_MESSAGES'],
			userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD']
		});
	}

	async exec(message: BushMessage | BushSlashMessage, args: { prefix?: string }): Promise<unknown> {
		const oldPrefix = await message.guild.getSetting('prefix');
		await message.guild.setSetting('prefix', args.prefix ?? client.config.prefix);
		if (args.prefix) {
			return await message.util.send({
				content: `${util.emojis.success} changed the server's prefix ${oldPrefix ? `from \`${oldPrefix}\`` : ''} to \`${
					args.prefix
				}\`.`,
				allowedMentions: AllowedMentions.none()
			});
		} else {
			return await message.util.send({
				content: `${util.emojis.success} reset the server's prefix to \`${client.config.prefix}\`.`,
				allowedMentions: AllowedMentions.none()
			});
		}
	}
}