feat(Interaction): add guild guard (#5955)

* feat(Interaction): add guild guard

* fix: remove possibly uncached getters & duplicate method

* fix: boolean ensuring

Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>

Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
This commit is contained in:
Papageorgiadis Savvas
2021-06-29 22:35:52 +03:00
committed by GitHub
parent 706c6eae60
commit 87e8cdd3eb
2 changed files with 9 additions and 0 deletions

View File

@@ -105,6 +105,14 @@ class Interaction extends Base {
return this.client.guilds.cache.get(this.guildID) ?? null;
}
/**
* Indicates whether this interaction is received from a guild.
* @returns {boolean}
*/
inGuild() {
return Boolean(this.guildID && this.member);
}
/**
* Indicates whether this interaction is a command interaction.
* @returns {boolean}

1
typings/index.d.ts vendored
View File

@@ -1212,6 +1212,7 @@ declare module 'discord.js' {
public type: InteractionType;
public user: User;
public version: number;
public inGuild(): boolean;
public isButton(): this is ButtonInteraction;
public isCommand(): this is CommandInteraction;
public isMessageComponent(): this is MessageComponentInteraction;