diff --git a/backend/src/plugins/ModActions/functions/banUserId.ts b/backend/src/plugins/ModActions/functions/banUserId.ts index 6a9dc7d5..4d576a60 100644 --- a/backend/src/plugins/ModActions/functions/banUserId.ts +++ b/backend/src/plugins/ModActions/functions/banUserId.ts @@ -1,4 +1,4 @@ -import { DiscordAPIError, Snowflake, User } from "discord.js"; +import { DiscordAPIError, Snowflake } from "discord.js"; import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; import { CaseTypes } from "../../../data/CaseTypes"; @@ -10,6 +10,7 @@ import { createUserNotificationError, DAYS, notifyUser, + resolveMember, resolveUser, SECONDS, ucfirst, @@ -42,8 +43,9 @@ export async function banUserId( } // Attempt to message the user *before* banning them, as doing it after may not be possible + const member = await resolveMember(pluginData.client, pluginData.guild, userId); let notifyResult: UserNotificationResult = { method: null, success: true }; - if (reason && user instanceof User) { + if (reason && member) { const contactMethods = banOptions?.contactMethods ? banOptions.contactMethods : getDefaultContactMethods(pluginData, "ban"); @@ -61,7 +63,7 @@ export async function banUserId( }), ); - notifyResult = await notifyUser(user, banMessage, contactMethods); + notifyResult = await notifyUser(member.user, banMessage, contactMethods); } else if (banTime && config.tempban_message) { const banMessage = await renderTemplate( config.tempban_message, @@ -75,7 +77,7 @@ export async function banUserId( }), ); - notifyResult = await notifyUser(user, banMessage, contactMethods); + notifyResult = await notifyUser(member.user, banMessage, contactMethods); } else { notifyResult = createUserNotificationError("No ban/tempban message specified in config"); } diff --git a/backend/src/plugins/ModActions/functions/kickMember.ts b/backend/src/plugins/ModActions/functions/kickMember.ts index 89559364..d54dfd15 100644 --- a/backend/src/plugins/ModActions/functions/kickMember.ts +++ b/backend/src/plugins/ModActions/functions/kickMember.ts @@ -24,7 +24,7 @@ export async function kickMember( // Attempt to message the user *before* kicking them, as doing it after may not be possible let notifyResult: UserNotificationResult = { method: null, success: true }; - if (reason) { + if (reason && member) { const contactMethods = kickOptions?.contactMethods ? kickOptions.contactMethods : getDefaultContactMethods(pluginData, "kick"); diff --git a/backend/src/plugins/Mutes/functions/muteUser.ts b/backend/src/plugins/Mutes/functions/muteUser.ts index 8d9bf1e6..5d23a916 100644 --- a/backend/src/plugins/Mutes/functions/muteUser.ts +++ b/backend/src/plugins/Mutes/functions/muteUser.ts @@ -1,4 +1,4 @@ -import { Snowflake, User } from "discord.js"; +import { Snowflake } from "discord.js"; import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; import { CaseTypes } from "../../../data/CaseTypes"; @@ -191,7 +191,7 @@ export async function muteUser( }), )); - if (muteMessage && user instanceof User) { + if (muteMessage && member) { let contactMethods: UserNotificationMethod[] = []; if (muteOptions?.contactMethods) { @@ -211,7 +211,7 @@ export async function muteUser( } } - notifyResult = await notifyUser(user, muteMessage, contactMethods); + notifyResult = await notifyUser(member.user, muteMessage, contactMethods); } // Create/update a case