diff --git a/src/structures/APIMessage.js b/src/structures/APIMessage.js index 6edd65785..d68ed0563 100644 --- a/src/structures/APIMessage.js +++ b/src/structures/APIMessage.js @@ -6,6 +6,7 @@ const MessageAttachment = require('./MessageAttachment'); const { browser } = require('../util/Constants'); const Util = require('../util/Util'); const { RangeError } = require('../errors'); +const MessageFlags = require('../util/MessageFlags'); /** * Represents a message to be sent to the API. @@ -63,6 +64,16 @@ class APIMessage { return this.target instanceof User || this.target instanceof GuildMember; } + /** + * Whether or not the target is a message + * @type {boolean} + * @readonly + */ + get isMessage() { + const Message = require('./Message'); + return this.target instanceof Message; + } + /** * Makes the content of this message. * @returns {?(string|string[])} @@ -126,6 +137,7 @@ class APIMessage { const content = this.makeContent(); const tts = Boolean(this.options.tts); + let nonce; if (typeof this.options.nonce !== 'undefined') { nonce = parseInt(this.options.nonce); @@ -149,6 +161,12 @@ class APIMessage { if (this.options.avatarURL) avatarURL = this.options.avatarURL; } + let flags; + if (this.isMessage) { + // eslint-disable-next-line eqeqeq + flags = this.options.flags != null ? new MessageFlags(this.options.flags).bitfield : this.target.flags.bitfield; + } + this.data = { content, tts, @@ -157,6 +175,7 @@ class APIMessage { embeds, username, avatar_url: avatarURL, + flags, }; return this; } diff --git a/src/structures/Message.js b/src/structures/Message.js index b32c874c1..0c856fdae 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -532,6 +532,23 @@ class Message extends Base { return this.client.fetchWebhook(this.webhookID); } + /** + * Suppresses or unsuppresses embeds on a message + * @param {boolean} [suppress=true] If the embeds should be suppressed or not + * @returns {Promise} + */ + suppressEmbeds(suppress = true) { + const flags = new MessageFlags(this.flags.bitfield); + + if (suppress) { + flags.add(MessageFlags.FLAGS.SUPPRESS_EMBEDS); + } else { + flags.remove(MessageFlags.FLAGS.SUPPRESS_EMBEDS); + } + + return this.edit({ flags }); + } + /** * Used mainly internally. Whether two messages are identical in properties. If you want to compare messages * without checking all the properties, use `message.id === message2.id`, which is much more efficient. This diff --git a/typings/index.d.ts b/typings/index.d.ts index 3f72f175a..d9daf995e 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -994,6 +994,7 @@ declare module 'discord.js' { public reply(options?: MessageOptions | MessageAdditions | APIMessage): Promise; public reply(options?: MessageOptions & { split?: false } | MessageAdditions | APIMessage): Promise; public reply(options?: MessageOptions & { split: true | SplitOptions } | MessageAdditions | APIMessage): Promise; + public suppressEmbeds(suppress?: boolean): Promise; public toJSON(): object; public toString(): string; public unpin(): Promise; @@ -2423,6 +2424,7 @@ declare module 'discord.js' { content?: string; embed?: MessageEmbedOptions | null; code?: string | boolean; + flags?: BitFieldResolvable; } interface MessageEmbedOptions {