Files
discordeno/helpers/messages/removeReaction.ts
2022-02-11 09:49:53 +00:00

30 lines
936 B
TypeScript

import type { Bot } from "../../bot.ts";
/** Removes a reaction from the given user on this message, defaults to bot. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
export async function removeReaction(
bot: Bot,
channelId: bigint,
messageId: bigint,
reaction: string,
options?: { userId?: bigint },
) {
if (reaction.startsWith("<:")) {
reaction = reaction.substring(2, reaction.length - 1);
} else if (reaction.startsWith("<a:")) {
reaction = reaction.substring(3, reaction.length - 1);
}
await bot.rest.runMethod<undefined>(
bot.rest,
"delete",
options?.userId
? bot.constants.endpoints.CHANNEL_MESSAGE_REACTION_USER(
channelId,
messageId,
encodeURIComponent(reaction),
options.userId,
)
: bot.constants.endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, encodeURIComponent(reaction)),
);
}