From 3131878cfbad8645ac8a46891470474ada1e5bd4 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 17 Oct 2021 19:52:56 +0300 Subject: [PATCH] fix(automod): fetch message user/member if missing from cache --- .../src/plugins/Automod/events/runAutomodOnMessage.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/src/plugins/Automod/events/runAutomodOnMessage.ts b/backend/src/plugins/Automod/events/runAutomodOnMessage.ts index 449352fe..8821d803 100644 --- a/backend/src/plugins/Automod/events/runAutomodOnMessage.ts +++ b/backend/src/plugins/Automod/events/runAutomodOnMessage.ts @@ -8,13 +8,17 @@ import { runAutomod } from "../functions/runAutomod"; import { AutomodContext, AutomodPluginType } from "../types"; import { performance } from "perf_hooks"; -export function runAutomodOnMessage( +export async function runAutomodOnMessage( pluginData: GuildPluginData, message: SavedMessage, isEdit: boolean, ) { - const user = pluginData.client.users.cache.get(message.user_id as Snowflake); - const member = pluginData.guild.members.cache.get(message.user_id as Snowflake); + const member = + pluginData.guild.members.cache.get(message.user_id) ?? + (await pluginData.guild.members.fetch(message.user_id).catch(() => undefined)); + const user = + pluginData.client.users.cache.get(message.user_id) ?? + (await pluginData.client.users.fetch(message.user_id).catch(() => undefined)); const context: AutomodContext = { timestamp: moment.utc(message.posted_at).valueOf(),