mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 11:33:30 +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 { browser } = require('../util/Constants');
|
||||||
const Util = require('../util/Util');
|
const Util = require('../util/Util');
|
||||||
const { RangeError } = require('../errors');
|
const { RangeError } = require('../errors');
|
||||||
|
const MessageFlags = require('../util/MessageFlags');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a message to be sent to the API.
|
* Represents a message to be sent to the API.
|
||||||
@@ -63,6 +64,16 @@ class APIMessage {
|
|||||||
return this.target instanceof User || this.target instanceof GuildMember;
|
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.
|
* Makes the content of this message.
|
||||||
* @returns {?(string|string[])}
|
* @returns {?(string|string[])}
|
||||||
@@ -126,6 +137,7 @@ class APIMessage {
|
|||||||
|
|
||||||
const content = this.makeContent();
|
const content = this.makeContent();
|
||||||
const tts = Boolean(this.options.tts);
|
const tts = Boolean(this.options.tts);
|
||||||
|
|
||||||
let nonce;
|
let nonce;
|
||||||
if (typeof this.options.nonce !== 'undefined') {
|
if (typeof this.options.nonce !== 'undefined') {
|
||||||
nonce = parseInt(this.options.nonce);
|
nonce = parseInt(this.options.nonce);
|
||||||
@@ -149,6 +161,12 @@ class APIMessage {
|
|||||||
if (this.options.avatarURL) avatarURL = this.options.avatarURL;
|
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 = {
|
this.data = {
|
||||||
content,
|
content,
|
||||||
tts,
|
tts,
|
||||||
@@ -157,6 +175,7 @@ class APIMessage {
|
|||||||
embeds,
|
embeds,
|
||||||
username,
|
username,
|
||||||
avatar_url: avatarURL,
|
avatar_url: avatarURL,
|
||||||
|
flags,
|
||||||
};
|
};
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -532,6 +532,23 @@ class Message extends Base {
|
|||||||
return this.client.fetchWebhook(this.webhookID);
|
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
|
* 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
|
* 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 | MessageAdditions | APIMessage): Promise<Message>;
|
||||||
public reply(options?: MessageOptions & { split?: false } | 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 reply(options?: MessageOptions & { split: true | SplitOptions } | MessageAdditions | APIMessage): Promise<Message[]>;
|
||||||
|
public suppressEmbeds(suppress?: boolean): Promise<Message>;
|
||||||
public toJSON(): object;
|
public toJSON(): object;
|
||||||
public toString(): string;
|
public toString(): string;
|
||||||
public unpin(): Promise<Message>;
|
public unpin(): Promise<Message>;
|
||||||
@@ -2423,6 +2424,7 @@ declare module 'discord.js' {
|
|||||||
content?: string;
|
content?: string;
|
||||||
embed?: MessageEmbedOptions | null;
|
embed?: MessageEmbedOptions | null;
|
||||||
code?: string | boolean;
|
code?: string | boolean;
|
||||||
|
flags?: BitFieldResolvable<MessageFlagsString>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MessageEmbedOptions {
|
interface MessageEmbedOptions {
|
||||||
|
|||||||
Reference in New Issue
Block a user