import { RESTJSONErrorCodes as DiscordApiErrors } from 'discord-api-types/v9' ; import { DiscordAPIError , Message , MessageReaction , PartialMessage , PartialMessageReaction , PartialUser , User , } from 'discord.js' ; const IGNORED_ERRORS = [ DiscordApiErrors . UnknownChannel , DiscordApiErrors . UnknownMessage , DiscordApiErrors . MissingAccess , ] ; export class PartialUtils { public static async fillUser ( user ) { if ( user . partial ) { try { return await user . fetch ( ) ; } catch ( error ) { if ( error instanceof DiscordAPIError && IGNORED_ERRORS . includes ( error . code ) ) { return ; } else { throw error ; } } } return user as User ; } public static async fillMessage ( msg ) { if ( msg . partial ) { try { return await msg . fetch ( ) ; } catch ( error ) { if ( error instanceof DiscordAPIError && IGNORED_ERRORS . includes ( error . code ) ) { return ; } else { throw error ; } } } return msg as Message ; } public static async fillReaction ( msgReaction ) { if ( msgReaction . partial ) { try { msgReaction = await msgReaction . fetch ( ) ; } catch ( error ) { if ( error instanceof DiscordAPIError && IGNORED_ERRORS . includes ( error . code ) ) { return ; } else { throw error ; } } } msgReaction . message = await this . fillMessage ( msgReaction . message ) ; if ( ! msgReaction . message ) { return ; } return msgReaction as MessageReaction ; } }