summaryrefslogtreecommitdiff
path: root/server/src/commands/reaction/Remove.ts
blob: 0a58cddfba41be7df4ee8a3ea6ed167accc9c75a (plain) (blame)
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
58
59
60
61
import { Command } from 'discord-akairo';
import { Message, TextChannel } from 'discord.js';
import { Reaction } from '../../database/models/ReactionModel';

export default class RemoveReaction extends Command {
    public constructor() {
        super('reactionremove', {
            aliases: ['reactionremove', 'reactionrm', 'reactiondelete', 'reactiondel'],
            category: 'reactions',
            description: {
                content: 'Removes a reaction from a message via an discriminator.',
                usage: '[discriminator]',
                examples: [
                    '[fV9k]'
                ]
            },
            ratelimit: 3,
            userPermissions: ['MANAGE_ROLES'],
			channel: 'guild',
			args: [
				{
					id: 'reaction',
					type: (msg: Message, str: string): Reaction | null => {
						const req = this.client.settings.cache.reactions.find(r => r.id === str && r.guildID === msg.guild!.id);
						if (!req) return null;
						return req;
					},
					match: 'rest',
					prompt: {
						start: "Please provide the unique identifier for the reaction you'd like to delete.",
						retry:
							"Please provide a valid identifier for the reaction role you'd like to delete. You can also delete the whole message to delete reaction roles on it.",
					},
				},
			],
        });
    }
    
	public async exec(msg: Message, { reaction }: { reaction: Reaction }): Promise<Message | Message[] | void> {
		this.client.logger.info(reaction);
		try {
			const chan = this.client.channels.cache.get(reaction.channelID) as TextChannel;
			if (!chan) throw new Error("That channel doesn't exist!");
			const message = await chan.messages.fetch(reaction.messageID);
			if (!message) throw new Error("That message doesn't exist!");
			await message.reactions.cache.get(reaction.emoji)!.users.remove(this.client.user!.id);
		} catch (err) {
			this.client.logger.error(`[ERROR in REMOVE CMD]: ${err}.`);
		}

		this.client.settings.set(
			'reaction',
			{ messageID: reaction.messageID },
			{
				active: false,
			},
		);

		return msg.reply('successfully deleted that reaction role.');
	}
}