Skip to content

Commit

Permalink
feat(Interaction): add guild guard (#5955)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
papsavas and NotSugden committed Jun 29, 2021
1 parent 706c6ea commit 87e8cdd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/structures/Interaction.js
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -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;
Expand Down

0 comments on commit 87e8cdd

Please sign in to comment.