aboutsummaryrefslogtreecommitdiff
path: root/src/commands/config/muteRole.ts
blob: f51c5cefc0c74a957d49b4be7155defc71886a0a (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
57
import { Role } from 'discord.js';
import { BushCommand } from '../../lib/extensions/BushCommand';
import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage';
import { BushMessage } from '../../lib/extensions/BushMessage';
import { Guild } from '../../lib/models';
import AllowedMentions from '../../lib/utils/AllowedMentions';

export default class MuteRoleCommand extends BushCommand {
	constructor() {
		super('muteRole', {
			aliases: ['muterole'],
			category: 'config',
			description: {
				content: 'Set the prefix of the current server (resets to default if prefix is not given)',
				usage: 'prefix [prefix]',
				examples: ['prefix', 'prefix +']
			},
			clientPermissions: ['SEND_MESSAGES'],
			userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'],
			args: [
				{
					id: 'role',
					type: 'role',
					prompt: {
						start: "What would you like to set the server's mute role to?",
						retry: '{error} Choose a valid role.',
						optional: false
					}
				}
			],
			slash: true,
			slashOptions: [
				{
					type: 'ROLE',
					name: 'role',
					description: 'The mute role for this server.',
					required: true
				}
			]
		});
	}

	async exec(message: BushMessage | BushSlashMessage, args: { role: Role }): Promise<void> {
		let row = await Guild.findByPk(message.guild.id);
		if (!row) {
			row = Guild.build({
				id: message.guild.id
			});
		}
		row.muteRole = args.role.id;
		await row.save();
		await message.util.send({
			content: `${this.client.util.emojis.success} Changed the mute role to <@&${args.role.id}>.`,
			allowedMentions: AllowedMentions.none()
		});
	}
}