From c50fb39b42f8e2c5d58c3f73ed859b5fd1d93fa4 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 15:01:32 +0200 Subject: [PATCH 1/9] deleteServer to deleteGuild --- src/helpers/guilds/{delete_server.ts => delete_guild.ts} | 5 ++--- src/helpers/mod.ts | 6 +++--- src/structures/guild.ts | 6 +++--- tests/guilds/delete_server.ts | 6 +++--- tests/ws/start_bot.ts | 4 ++-- 5 files changed, 13 insertions(+), 14 deletions(-) rename src/helpers/guilds/{delete_server.ts => delete_guild.ts} (68%) diff --git a/src/helpers/guilds/delete_server.ts b/src/helpers/guilds/delete_guild.ts similarity index 68% rename from src/helpers/guilds/delete_server.ts rename to src/helpers/guilds/delete_guild.ts index 8dcf42eaf..496ac3088 100644 --- a/src/helpers/guilds/delete_server.ts +++ b/src/helpers/guilds/delete_guild.ts @@ -1,9 +1,8 @@ import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; -/** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. - */ -export async function deleteServer(guildId: string) { +/** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */ +export async function deleteGuild(guildId: string) { return await rest.runMethod( "delete", endpoints.GUILDS_BASE(guildId), diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 6991542d3..ee1de11cb 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -38,7 +38,7 @@ import { emojiURL } from "./emojis/emoji_url.ts"; import { getEmoji } from "./emojis/get_emoji.ts"; import { getEmojis } from "./emojis/get_emojis.ts"; import { createGuild } from "./guilds/create_guild.ts"; -import { deleteServer } from "./guilds/delete_server.ts"; +import { deleteGuild } from "./guilds/delete_guild.ts"; import { editGuild } from "./guilds/edit_guild.ts"; import { editWelcomeScreen } from "./guilds/edit_welcome_screen.ts"; import { editWidget } from "./guilds/edit_widget.ts"; @@ -147,13 +147,13 @@ export { deleteChannel, deleteChannelOverwrite, deleteEmoji, + deleteGuild, deleteGuildTemplate, deleteIntegration, deleteInvite, deleteMessage, deleteMessages, deleteRole, - deleteServer, deleteSlashCommand, deleteSlashResponse, deleteWebhook, @@ -295,7 +295,7 @@ export let helpers = { // guilds categoryChildren, createGuild, - deleteServer, + deleteGuild, editGuild, editWidget, editWelcomeScreen, diff --git a/src/structures/guild.ts b/src/structures/guild.ts index 4dda13665..562440c25 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -1,6 +1,6 @@ import { botId, eventHandlers } from "../bot.ts"; import { cache, cacheHandlers } from "../cache.ts"; -import { deleteServer } from "../helpers/guilds/delete_server.ts"; +import { deleteGuild } from "../helpers/guilds/delete_guild.ts"; import { editGuild } from "../helpers/guilds/edit_guild.ts"; import { getAuditLogs } from "../helpers/guilds/get_audit_logs.ts"; import { getBan } from "../helpers/guilds/get_ban.ts"; @@ -79,7 +79,7 @@ const baseGuild: Partial = { return guildSplashURL(this.id!, this.splash!, size, format); }, delete() { - return deleteServer(this.id!); + return deleteGuild(this.id!); }, edit(options) { return editGuild(this.id!, options); @@ -272,7 +272,7 @@ export interface DiscordenoGuild extends format?: DiscordImageFormat, ): string | undefined; /** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */ - delete(): ReturnType; + delete(): ReturnType; /** Leave a guild */ leave(): ReturnType; /** Edit the server. Requires the MANAGE_GUILD permission. */ diff --git a/tests/guilds/delete_server.ts b/tests/guilds/delete_server.ts index 96dd306d9..52c2b9955 100644 --- a/tests/guilds/delete_server.ts +++ b/tests/guilds/delete_server.ts @@ -1,7 +1,7 @@ import { cache } from "../../src/cache.ts"; -import { deleteServer } from "../../src/helpers/guilds/delete_server.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; +import { deleteGuild } from "../../src/helpers/guilds/delete_guild.ts"; import { delayUntil } from "../util/delay_until.ts"; +import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; Deno.test({ name: "[guild] delete a guild", @@ -13,7 +13,7 @@ Deno.test({ throw new Error("The guild was not cached so impossible to delete."); } - await deleteServer(tempData.guildId); + await deleteGuild(tempData.guildId); await delayUntil(10000, () => !cache.guilds.has(tempData.guildId)); if (cache.guilds.has(tempData.guildId)) { diff --git a/tests/ws/start_bot.ts b/tests/ws/start_bot.ts index f6abcfc97..50992e855 100644 --- a/tests/ws/start_bot.ts +++ b/tests/ws/start_bot.ts @@ -1,6 +1,6 @@ import { botId, startBot } from "../../src/bot.ts"; import { cache } from "../../src/cache.ts"; -import { deleteServer } from "../../src/helpers/guilds/delete_server.ts"; +import { deleteGuild } from "../../src/helpers/guilds/delete_guild.ts"; import { delay } from "../../src/util/utils.ts"; import { ws } from "../../src/ws/ws.ts"; import { assertExists } from "../deps.ts"; @@ -49,7 +49,7 @@ Deno.test({ // DELETE GUILDS IF LESS THAN 10 SERVERS AS SAFETY MEASURE if (cache.guilds.size <= 10) { - for (const guild of cache.guilds.values()) await deleteServer(guild.id); + for (const guild of cache.guilds.values()) await deleteGuild(guild.id); } // Assertions From b28ab09f7e6bd403d017e16a2b6a0a97826565f4 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 15:01:44 +0200 Subject: [PATCH 2/9] remove rawGateway --- src/types/discordeno/eventHandlers.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/types/discordeno/eventHandlers.ts b/src/types/discordeno/eventHandlers.ts index f60fda6e2..8dba6659e 100644 --- a/src/types/discordeno/eventHandlers.ts +++ b/src/types/discordeno/eventHandlers.ts @@ -161,8 +161,6 @@ export interface EventHandlers { ) => unknown; /** Sent before every event execution. Discordeno will not await its execution. */ raw?: (data: GatewayPayload) => unknown; - // TODO: remove this? - // rawGateway?: (data: unknown) => unknown; /** Sent when all shards went ready. */ ready?: () => unknown; /** Sent when a user adds a reaction to a message. */ From 7aab8a803096780075cb5d5e9904c89f987bdeeb Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 15:04:44 +0200 Subject: [PATCH 3/9] add: addToCache option --- src/helpers/members/get_members.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/helpers/members/get_members.ts b/src/helpers/members/get_members.ts index b51fff45a..202c4a70d 100644 --- a/src/helpers/members/get_members.ts +++ b/src/helpers/members/get_members.ts @@ -19,7 +19,10 @@ import { ws } from "../../ws/ws.ts"; * REST(this function): 50/s global(across all shards) rate limit with ALL requests this included * GW(fetchMembers): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is 960/m. */ -export async function getMembers(guildId: string, options?: ListGuildMembers) { +export async function getMembers( + guildId: string, + options?: ListGuildMembers & { addToCache?: boolean }, +) { if (!(ws.identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS)) { throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS); } @@ -61,11 +64,13 @@ export async function getMembers(guildId: string, options?: ListGuildMembers) { guildId, ); - await cacheHandlers.set( - "members", - discordenoMember.id, - discordenoMember, - ); + if (options?.addToCache !== false) { + await cacheHandlers.set( + "members", + discordenoMember.id, + discordenoMember, + ); + } return discordenoMember; }), From 5b314d0b9ec05b00d2694969ca59a3efbfad0548 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 15:13:46 +0200 Subject: [PATCH 4/9] typos --- src/util/permissions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/permissions.ts b/src/util/permissions.ts index 3607a561f..1eb5b65a9 100644 --- a/src/util/permissions.ts +++ b/src/util/permissions.ts @@ -201,9 +201,9 @@ export async function getMissingGuildPermissions( member: string | DiscordenoMember, permissions: PermissionStrings[], ) { - // First we need the role permissino bits this member has + // First we need the role permission bits this member has const permissionBits = await calculateBasePermissions(guild, member); - // Second returnn the members missing permissions + // Second return the members missing permissions return missingPermissions(permissionBits, permissions); } From a7de104b9afd5c152f12dc1539c9fe5efd907480 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 15:13:58 +0200 Subject: [PATCH 5/9] calculatePermissions should take a string --- src/helpers/channels/clone_channel.ts | 4 ++-- src/util/permissions.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/helpers/channels/clone_channel.ts b/src/helpers/channels/clone_channel.ts index 76ca0a7b0..e84e039e0 100644 --- a/src/helpers/channels/clone_channel.ts +++ b/src/helpers/channels/clone_channel.ts @@ -29,8 +29,8 @@ export async function cloneChannel(channelId: string, reason?: string) { ) => ({ id: overwrite.id, type: overwrite.type, - allow: calculatePermissions(BigInt(overwrite.allow)), - deny: calculatePermissions(BigInt(overwrite.deny)), + allow: calculatePermissions(overwrite.allow), + deny: calculatePermissions(overwrite.deny), })), }; diff --git a/src/util/permissions.ts b/src/util/permissions.ts index 1eb5b65a9..90e187562 100644 --- a/src/util/permissions.ts +++ b/src/util/permissions.ts @@ -268,13 +268,13 @@ export function requireBotChannelPermissions( } /** This function converts a bitwise string to permission strings */ -export function calculatePermissions(permissionBits: bigint) { +export function calculatePermissions(permissionBits: string) { return Object.keys(DiscordBitwisePermissionFlags).filter((permission) => { // Since Object.keys() not only returns the permission names but also the bit values we need to return false if it is a Number if (Number(permission)) return false; // Check if permissionBits has this permission return ( - permissionBits & + BigInt(permissionBits) & BigInt(DiscordBitwisePermissionFlags[permission as PermissionStrings]) ); }) as PermissionStrings[]; From 8c347747dd0c91af3cc0efa99a9705d6910011c8 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 15:22:48 +0200 Subject: [PATCH 6/9] delete: removeUserReaction --- src/helpers/messages/remove_reaction.ts | 17 ++++++++++-- src/helpers/messages/remove_user_reaction.ts | 29 -------------------- src/helpers/mod.ts | 3 -- src/structures/message.ts | 9 ++++-- tests/messages/remove_user_reaction.ts | 11 ++------ 5 files changed, 24 insertions(+), 45 deletions(-) delete mode 100644 src/helpers/messages/remove_user_reaction.ts diff --git a/src/helpers/messages/remove_reaction.ts b/src/helpers/messages/remove_reaction.ts index b8bd2f707..1be275af9 100644 --- a/src/helpers/messages/remove_reaction.ts +++ b/src/helpers/messages/remove_reaction.ts @@ -1,12 +1,18 @@ import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; +import { requireBotChannelPermissions } from "../../util/permissions.ts"; -/** Removes a reaction from the bot on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */ +/** 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( channelId: string, messageId: string, reaction: string, + userId?: string, ) { + if (userId) { + await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); + } + if (reaction.startsWith("<:")) { reaction = reaction.substring(2, reaction.length - 1); } else if (reaction.startsWith("( "delete", - endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction), + userId + ? endpoints.CHANNEL_MESSAGE_REACTION_USER( + channelId, + messageId, + reaction, + userId, + ) + : endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction), ); } diff --git a/src/helpers/messages/remove_user_reaction.ts b/src/helpers/messages/remove_user_reaction.ts deleted file mode 100644 index 7f5b67dfd..000000000 --- a/src/helpers/messages/remove_user_reaction.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { rest } from "../../rest/rest.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotChannelPermissions } from "../../util/permissions.ts"; - -/** Removes a reaction from the specified user on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */ -export async function removeUserReaction( - channelId: string, - messageId: string, - reaction: string, - userId: string, -) { - await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); - - if (reaction.startsWith("<:")) { - reaction = reaction.substring(2, reaction.length - 1); - } else if (reaction.startsWith("( - "delete", - endpoints.CHANNEL_MESSAGE_REACTION_USER( - channelId, - messageId, - reaction, - userId, - ), - ); -} diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index ee1de11cb..483f7378f 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -93,7 +93,6 @@ import { publishMessage } from "./messages/publish_message.ts"; import { removeAllReactions } from "./messages/remove_all_reactions.ts"; import { removeReaction } from "./messages/remove_reaction.ts"; import { removeReactionEmoji } from "./messages/remove_reaction_emoji.ts"; -import { removeUserReaction } from "./messages/remove_user_reaction.ts"; import { sendMessage } from "./messages/send_message.ts"; import { unpin, unpinMessage } from "./messages/unpin_message.ts"; import { editBotStatus } from "./misc/edit_bot_status.ts"; @@ -240,7 +239,6 @@ export { removeReaction, removeReactionEmoji, removeRole, - removeUserReaction, sendDirectMessage, sendInteractionResponse, sendMessage, @@ -361,7 +359,6 @@ export let helpers = { removeAllReactions, removeReactionEmoji, removeReaction, - removeUserReaction, sendMessage, unpinMessage, // misc diff --git a/src/structures/message.ts b/src/structures/message.ts index 9f24937ee..add15b8c4 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -121,8 +121,8 @@ const baseMessage: Partial = { removeReactionEmoji(reaction) { return removeReactionEmoji(this.channelId!, this.id!, reaction); }, - removeReaction(reaction) { - return removeReaction(this.channelId!, this.id!, reaction); + removeReaction(reaction, userId) { + return removeReaction(this.channelId!, this.id!, reaction, userId); }, }; @@ -255,5 +255,8 @@ export interface DiscordenoMessage /** Remove all reactions */ removeReactionEmoji(reaction: string): ReturnType; /** Remove all reactions */ - removeReaction(reaction: string): ReturnType; + removeReaction( + reaction: string, + userId?: string, + ): ReturnType; } diff --git a/tests/messages/remove_user_reaction.ts b/tests/messages/remove_user_reaction.ts index 0662738b4..4c3859c03 100644 --- a/tests/messages/remove_user_reaction.ts +++ b/tests/messages/remove_user_reaction.ts @@ -1,12 +1,7 @@ -import { - addReaction, - cache, - removeUserReaction, - sendMessage, -} from "../../mod.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; +import { addReaction, cache, removeReaction, sendMessage } from "../../mod.ts"; import { assertEquals, assertExists } from "../deps.ts"; import { delayUntil } from "../util/delay_until.ts"; +import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; async function ifItFailsBlameWolf(type: "getter" | "raw") { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -32,7 +27,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { assertEquals(await cache.messages.get(message.id)?.reactions?.length, 1); if (type === "raw") { - await removeUserReaction( + await removeReaction( message.channelId, message.id, "❤", From 9d26a26ae6dbbbde0e64e046f85d299198f31134 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 15:23:11 +0200 Subject: [PATCH 7/9] fix: message structure remove reaction wrong comments --- src/structures/message.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/structures/message.ts b/src/structures/message.ts index add15b8c4..6e8f22bdf 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -250,11 +250,11 @@ export interface DiscordenoMessage timeout?: number, reason?: string, ): Promise; - /** Remove all reactions */ + /** Removes all reactions for all emojis on this message */ removeAllReactions(): ReturnType; - /** Remove all reactions */ + /** Removes all reactions for a single emoji on this message */ removeReactionEmoji(reaction: string): ReturnType; - /** Remove all reactions */ + /** Removes a reaction from the given user on this message, defaults to bot */ removeReaction( reaction: string, userId?: string, From ce5f8909730cfcd89cb9f7ecd4a85a3b1ff81c7d Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 15:32:08 +0200 Subject: [PATCH 8/9] change removeUserReaction tests --- tests/messages/remove_reaction.ts | 29 ++++++++++-- tests/messages/remove_user_reaction.ts | 64 -------------------------- tests/mod.ts | 1 - 3 files changed, 25 insertions(+), 69 deletions(-) delete mode 100644 tests/messages/remove_user_reaction.ts diff --git a/tests/messages/remove_reaction.ts b/tests/messages/remove_reaction.ts index 3bf96826c..722631769 100644 --- a/tests/messages/remove_reaction.ts +++ b/tests/messages/remove_reaction.ts @@ -1,9 +1,9 @@ import { addReaction, cache, removeReaction, sendMessage } from "../../mod.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertEquals, assertExists } from "../deps.ts"; import { delayUntil } from "../util/delay_until.ts"; +import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; -async function ifItFailsBlameWolf(type: "getter" | "raw") { +async function ifItFailsBlameWolf(type: "getter" | "raw", user = false) { const message = await sendMessage(tempData.channelId, "Hello World!"); // Assertions @@ -27,9 +27,14 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { assertEquals(await cache.messages.get(message.id)?.reactions?.length, 1); if (type === "raw") { - await removeReaction(message.channelId, message.id, "❤"); + await removeReaction( + message.channelId, + message.id, + "❤", + user ? message.author.id : undefined, + ); } else { - await message.removeReaction("❤"); + await message.removeReaction("❤", user ? message.author.id : undefined); } // Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed @@ -57,3 +62,19 @@ Deno.test({ }, ...defaultTestOptions, }); + +Deno.test({ + name: "[message] remove a user reaction", + async fn() { + await ifItFailsBlameWolf("raw", true); + }, + ...defaultTestOptions, +}); + +Deno.test({ + name: "[message] message.removeReaction with user", + async fn() { + await ifItFailsBlameWolf("getter", true); + }, + ...defaultTestOptions, +}); diff --git a/tests/messages/remove_user_reaction.ts b/tests/messages/remove_user_reaction.ts deleted file mode 100644 index 4c3859c03..000000000 --- a/tests/messages/remove_user_reaction.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { addReaction, cache, removeReaction, sendMessage } from "../../mod.ts"; -import { assertEquals, assertExists } from "../deps.ts"; -import { delayUntil } from "../util/delay_until.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; - -async function ifItFailsBlameWolf(type: "getter" | "raw") { - const message = await sendMessage(tempData.channelId, "Hello World!"); - - // Assertions - assertExists(message); - // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => cache.messages.has(message.id)); - // Make sure the message was created. - if (!cache.messages.has(message.id)) { - throw new Error("The message seemed to be sent but it was not cached."); - } - - // Add reactions to the message - await addReaction(message.channelId, message.id, "❤"); - // Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed - await delayUntil( - 10000, - () => cache.messages.get(message.id)?.reactions?.length === 1, - ); - - // Be sure that the message has the reactions - assertEquals(await cache.messages.get(message.id)?.reactions?.length, 1); - - if (type === "raw") { - await removeReaction( - message.channelId, - message.id, - "❤", - message.author.id, - ); - } else { - //await message.removeUserReaction("❤", message.author.id); - } - - // Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed - await delayUntil( - 10000, - () => cache.messages.get(message.id)?.reactions === undefined, - ); - - // Check if the reactions has been deleted - assertEquals(await cache.messages.get(message.id)?.reactions, undefined); -} - -Deno.test({ - name: "[message] remove a user reaction", - async fn() { - await ifItFailsBlameWolf("raw"); - }, - ...defaultTestOptions, -}); -/* -Deno.test({ - name: "[message] message.removeReaction()", - async fn() { - await ifItFailsBlameWolf("getter"); - }, - ...defaultTestOptions, -});*/ diff --git a/tests/mod.ts b/tests/mod.ts index e1240004b..34fbc07bd 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -48,7 +48,6 @@ import "./messages/add_reactions.ts"; import "./messages/remove_all_reactions.ts"; import "./messages/remove_reaction.ts"; import "./messages/remove_reaction_emoji.ts"; -import "./messages/remove_user_reaction.ts"; import "./messages/create_message.ts"; import "./messages/delete_message.ts"; import "./messages/delete_messages.ts"; From 5a526c809b18a17c7422fe61434bdd7e7f53620f Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 30 Apr 2021 18:57:44 +0200 Subject: [PATCH 9/9] to an option object --- src/helpers/messages/remove_reaction.ts | 8 ++++---- src/structures/message.ts | 2 +- tests/messages/remove_reaction.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/helpers/messages/remove_reaction.ts b/src/helpers/messages/remove_reaction.ts index 1be275af9..36866d010 100644 --- a/src/helpers/messages/remove_reaction.ts +++ b/src/helpers/messages/remove_reaction.ts @@ -7,9 +7,9 @@ export async function removeReaction( channelId: string, messageId: string, reaction: string, - userId?: string, + options?: { userId?: string }, ) { - if (userId) { + if (options?.userId) { await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); } @@ -21,12 +21,12 @@ export async function removeReaction( return await rest.runMethod( "delete", - userId + options?.userId ? endpoints.CHANNEL_MESSAGE_REACTION_USER( channelId, messageId, reaction, - userId, + options.userId, ) : endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction), ); diff --git a/src/structures/message.ts b/src/structures/message.ts index 6e8f22bdf..014e6ea37 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -122,7 +122,7 @@ const baseMessage: Partial = { return removeReactionEmoji(this.channelId!, this.id!, reaction); }, removeReaction(reaction, userId) { - return removeReaction(this.channelId!, this.id!, reaction, userId); + return removeReaction(this.channelId!, this.id!, reaction, { userId }); }, }; diff --git a/tests/messages/remove_reaction.ts b/tests/messages/remove_reaction.ts index 722631769..0d02e83ef 100644 --- a/tests/messages/remove_reaction.ts +++ b/tests/messages/remove_reaction.ts @@ -31,7 +31,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", user = false) { message.channelId, message.id, "❤", - user ? message.author.id : undefined, + user ? { userId: message.author.id } : undefined, ); } else { await message.removeReaction("❤", user ? message.author.id : undefined);