From 095bd77515aa31bb0e95a350b4355980fea9268d Mon Sep 17 00:00:00 2001 From: Jaworek Date: Sat, 25 Feb 2023 15:41:10 +0100 Subject: [PATCH] feat(AutoModerationActionExecution): add `channel`, `user` and `member` getters (#9142) * feat(AutoModerationActionExecution): add channel prop * feat(AutoModerationActionExecution): add user prop * fix: sintax * feat: add guildmember getter * Apply suggestions from code review Co-authored-by: Almeida --------- Co-authored-by: Almeida Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../AutoModerationActionExecution.js | 27 +++++++++++++++++++ packages/discord.js/typings/index.d.ts | 3 +++ 2 files changed, 30 insertions(+) diff --git a/packages/discord.js/src/structures/AutoModerationActionExecution.js b/packages/discord.js/src/structures/AutoModerationActionExecution.js index ca40856d0a4f..ca09a7fbf16f 100644 --- a/packages/discord.js/src/structures/AutoModerationActionExecution.js +++ b/packages/discord.js/src/structures/AutoModerationActionExecution.js @@ -84,6 +84,33 @@ class AutoModerationActionExecution { get autoModerationRule() { return this.guild.autoModerationRules.cache.get(this.ruleId) ?? null; } + + /** + * The channel where this action was triggered from. + * @type {?TextBasedChannel} + * @readonly + */ + get channel() { + return this.guild.channels.cache.get(this.channelId) ?? null; + } + + /** + * The user that triggered this action. + * @type {?User} + * @readonly + */ + get user() { + return this.guild.client.users.cache.get(this.userId) ?? null; + } + + /** + * The guild member that triggered this action. + * @type {?GuildMember} + * @readonly + */ + get member() { + return this.guild.members.cache.get(this.userId) ?? null; + } } module.exports = AutoModerationActionExecution; diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index c67988c66cf6..75f1d9bc26b6 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -341,8 +341,11 @@ export class AutoModerationActionExecution { public action: AutoModerationAction; public ruleId: Snowflake; public ruleTriggerType: AutoModerationRuleTriggerType; + public get user(): User | null; public userId: Snowflake; + public get channel(): TextBasedChannel | null; public channelId: Snowflake | null; + public get member(): GuildMember | null; public messageId: Snowflake | null; public alertSystemMessageId: Snowflake | null; public content: string;