mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(Message): add support for flag editing / embed suppression (#3674)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<Message>}
|
||||
*/
|
||||
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
|
||||
|
||||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
@@ -994,6 +994,7 @@ declare module 'discord.js' {
|
||||
public reply(options?: MessageOptions | MessageAdditions | APIMessage): Promise<Message>;
|
||||
public reply(options?: MessageOptions & { split?: false } | MessageAdditions | APIMessage): Promise<Message>;
|
||||
public reply(options?: MessageOptions & { split: true | SplitOptions } | MessageAdditions | APIMessage): Promise<Message[]>;
|
||||
public suppressEmbeds(suppress?: boolean): Promise<Message>;
|
||||
public toJSON(): object;
|
||||
public toString(): string;
|
||||
public unpin(): Promise<Message>;
|
||||
@@ -2423,6 +2424,7 @@ declare module 'discord.js' {
|
||||
content?: string;
|
||||
embed?: MessageEmbedOptions | null;
|
||||
code?: string | boolean;
|
||||
flags?: BitFieldResolvable<MessageFlagsString>;
|
||||
}
|
||||
|
||||
interface MessageEmbedOptions {
|
||||
|
||||
Reference in New Issue
Block a user