From 7c6000c5e3dd9974fff0acff75594cfa7c754962 Mon Sep 17 00:00:00 2001 From: Ryan Munro Date: Fri, 17 Apr 2020 19:23:31 +1000 Subject: [PATCH] feat(ClientOptions): allow setting default allowedMentions (#4085) * feat(ClientOptions): add default allowedMentions * feat(ClientOptions): use default allowedMentions when not provided * Update src/structures/APIMessage.js Co-Authored-By: SpaceEEC * Update src/structures/APIMessage.js Co-Authored-By: SpaceEEC * fix(ClientOptions): default allowedMentions should be undefined Co-authored-by: SpaceEEC --- src/structures/APIMessage.js | 7 ++++++- src/util/Constants.js | 1 + typings/index.d.ts | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/structures/APIMessage.js b/src/structures/APIMessage.js index 3c8742558..86dab7446 100644 --- a/src/structures/APIMessage.js +++ b/src/structures/APIMessage.js @@ -176,6 +176,11 @@ class APIMessage { flags = this.options.flags != null ? new MessageFlags(this.options.flags).bitfield : this.target.flags.bitfield; } + const allowedMentions = + typeof this.options.allowedMentions === 'undefined' + ? this.target.client.options.allowedMentions + : this.options.allowedMentions; + this.data = { content, tts, @@ -184,7 +189,7 @@ class APIMessage { embeds, username, avatar_url: avatarURL, - allowed_mentions: this.options.allowedMentions, + allowed_mentions: allowedMentions, flags, }; return this; diff --git a/src/util/Constants.js b/src/util/Constants.js index b3c23914d..74a58ffe2 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -22,6 +22,7 @@ const browser = (exports.browser = typeof window !== 'undefined'); * @property {boolean} [fetchAllMembers=false] Whether to cache all guild members and users upon startup, as well as * upon joining a guild (should be avoided whenever possible) * @property {DisableMentionType} [disableMentions='none'] Default value for {@link MessageOptions#disableMentions} + * @property {MessageMentionOptions} [allowedMentions] Default value for {@link MessageOptions#allowedMentions} * @property {PartialType[]} [partials] Structures allowed to be partial. This means events can be emitted even when * they're missing all the data for a particular structure. See the "Partials" topic listed in the sidebar for some * important usage information, as partials require you to put checks in place when handling data. diff --git a/typings/index.d.ts b/typings/index.d.ts index 4646ffc08..2f18caf1c 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2233,6 +2233,7 @@ declare module 'discord.js' { messageSweepInterval?: number; fetchAllMembers?: boolean; disableMentions?: 'none' | 'all' | 'everyone'; + allowedMentions?: MessageMentionOptions; partials?: PartialTypes[]; restWsBridgeTimeout?: number; restTimeOffset?: number;