aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moderation/removeReactionEmoji.ts
blob: 3d274e1b83203092740303c8c7f9e6cfa0b4e699 (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
58
59
60
61
62
63
64
import { BushCommand, BushMessage } from '@lib';
import { Argument } from 'discord-akairo';
import { Emoji } from 'discord.js';

export default class RemoveReactionEmojiCommand extends BushCommand {
	public constructor() {
		super('removereactionemoji', {
			aliases: ['removereactionemoji', 'rre'],
			category: 'moderation',
			description: {
				content: 'Deleted all the reactions of a certain emoji from a message.',
				usage: 'removereactionemoji <message> <emoji>',
				examples: ['removereactionemoji 791413052347252786 <:omegaclown:782630946435366942>']
			},
			clientPermissions: ['MANAGE_MESSAGES', 'SEND_MESSAGES', 'EMBED_LINKS'],
			userPermissions: ['MANAGE_MESSAGES', 'MANAGE_EMOJIS'], // Can't undo the removal of 1000s of reactions
			args: [
				{
					id: 'messageToRemoveFrom',
					type: 'guildMessage',
					prompt: {
						start: 'What message would you like to remove a reaction from?',
						retry: '{error} Please pick a valid message.'
					}
				},
				{
					id: 'emoji',
					type: Argument.union('emoji', 'bigint'),
					match: 'restContent',
					prompt: {
						start: 'What emoji would you like to remove?',
						retry: '{error} Please pick a valid emoji.'
					}
				}
			],
			channel: 'guild'
		});
	}

	public async exec(
		message: BushMessage,
		{ messageToRemoveFrom, emoji }: { messageToRemoveFrom: BushMessage; emoji: Emoji | BigInt }
	): Promise<unknown> {
		const id = !['bigint', 'string'].includes(typeof emoji);
		const emojiID = !id ? `${emoji}` : (emoji as Emoji).id;
		const success = await messageToRemoveFrom.reactions.cache
			.get(emojiID)
			.remove()
			.catch(() => {});
		if (success) {
			return await message.util.reply(
				`${this.client.util.emojis.success} Removed all reactions of \`${
					id ? emojiID : emoji
				}\` from the message with the id of \`${messageToRemoveFrom.id}\`.`
			);
		} else {
			return await message.util.reply(
				`${this.client.util.emojis.error} There was an error removing all reactions of \`${
					id ? emojiID : emoji
				}\` from the message with the id of \`${messageToRemoveFrom.id}\`.`
			);
		}
	}
}