From e082a5d69363bc79ee85a75003d203471c2312da Mon Sep 17 00:00:00 2001 From: ayntee Date: Sat, 19 Dec 2020 13:24:38 +0400 Subject: [PATCH] fix: check if Message#guildID is present --- src/structures/message.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/structures/message.ts b/src/structures/message.ts index f0c8a26dd..75ccbc7d8 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -10,12 +10,15 @@ import { Role } from "./role.ts"; const baseMessage: Partial = { get guild() { + if (!this.guildID) return; return cache.guilds.get(this.guildID); }, get member() { + if (!this.author?.id) return; return cache.members.get(this.author?.id); }, get guildMember() { + if (!this.guildID) return; return this.member?.guilds.get(this.guildID); }, get link() { @@ -37,7 +40,7 @@ const baseMessage: Partial = { return deleteMessageByID(this.channelID!, this.id!, reason, delayMilliseconds); }, edit(content) { - return editMessage(this, content); + return editMessage(this as Message, content); }, pin() { return pin(this.channelID!, this.id!) @@ -171,6 +174,7 @@ export interface Message { referencedMessageID?: MessageCreateOptions | null; // GETTERS + /** The guild of this message. Can be undefined if not in cache or in DM */ guild?: Guild; /** The member for the user who sent the message. Can be undefined if not in cache or in dm. */ @@ -180,11 +184,11 @@ export interface Message { /** The url link to this message */ link: string; /** The role objects for all the roles that were mentioned in this message */ - mentionedRoles: Role[]; + mentionedRoles: (Role | undefined)[]; /** The channel objects for all the channels that were mentioned in this message. */ - mentionedChannels: Channel[]; + mentionedChannels: (Channel | undefined)[]; /** The member objects for all the members that were mentioned in this message. */ - mentionedMembers: Member[]; + mentionedMembers: (Member | undefined)[]; // METHODS