mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat: allow setting message flags when sending (#7312)
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { Buffer } = require('node:buffer');
|
const { Buffer } = require('node:buffer');
|
||||||
const { createComponent } = require('@discordjs/builders');
|
const { createComponent, Embed } = require('@discordjs/builders');
|
||||||
const { Embed } = require('@discordjs/builders');
|
const { MessageFlags } = require('discord-api-types/v9');
|
||||||
const { RangeError } = require('../errors');
|
const { RangeError } = require('../errors');
|
||||||
const DataResolver = require('../util/DataResolver');
|
const DataResolver = require('../util/DataResolver');
|
||||||
const MessageFlags = require('../util/MessageFlags');
|
|
||||||
const Util = require('../util/Util');
|
const Util = require('../util/Util');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -148,11 +147,13 @@ class MessagePayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let flags;
|
let flags;
|
||||||
if (this.isMessage || this.isMessageManager) {
|
if (typeof this.options.flags !== 'undefined' || this.isMessage || this.isMessageManager) {
|
||||||
// eslint-disable-next-line eqeqeq
|
// eslint-disable-next-line eqeqeq
|
||||||
flags = this.options.flags != null ? new MessageFlags(this.options.flags).bitfield : this.target.flags?.bitfield;
|
flags = this.options.flags != null ? new MessageFlags(this.options.flags).bitfield : this.target.flags?.bitfield;
|
||||||
} else if (isInteraction && this.options.ephemeral) {
|
}
|
||||||
flags = MessageFlags.FLAGS.EPHEMERAL;
|
|
||||||
|
if (isInteraction && this.options.ephemeral) {
|
||||||
|
flags |= MessageFlags.Ephemeral;
|
||||||
}
|
}
|
||||||
|
|
||||||
let allowedMentions =
|
let allowedMentions =
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ class Webhook {
|
|||||||
* @property {string} [avatarURL] Avatar URL override for the message
|
* @property {string} [avatarURL] Avatar URL override for the message
|
||||||
* @property {Snowflake} [threadId] The id of the thread in the channel to send to.
|
* @property {Snowflake} [threadId] The id of the thread in the channel to send to.
|
||||||
* <info>For interaction webhooks, this property is ignored</info>
|
* <info>For interaction webhooks, this property is ignored</info>
|
||||||
|
* @property {MessageFlags} [flags] Which flags to set for the message. Only `SUPPRESS_EMBEDS` can be set.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ class InteractionResponses {
|
|||||||
* @typedef {BaseMessageOptions} InteractionReplyOptions
|
* @typedef {BaseMessageOptions} InteractionReplyOptions
|
||||||
* @property {boolean} [ephemeral] Whether the reply should be ephemeral
|
* @property {boolean} [ephemeral] Whether the reply should be ephemeral
|
||||||
* @property {boolean} [fetchReply] Whether to fetch the reply
|
* @property {boolean} [fetchReply] Whether to fetch the reply
|
||||||
|
* @property {MessageFlags} [flags] Which flags to set for the message.
|
||||||
|
* Only `SUPPRESS_EMBEDS` and `EPHEMERAL` can be set.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ class TextBasedChannel {
|
|||||||
* @typedef {BaseMessageOptions} MessageOptions
|
* @typedef {BaseMessageOptions} MessageOptions
|
||||||
* @property {ReplyOptions} [reply] The options for replying to a message
|
* @property {ReplyOptions} [reply] The options for replying to a message
|
||||||
* @property {StickerResolvable[]} [stickers=[]] Stickers to send in the message
|
* @property {StickerResolvable[]} [stickers=[]] Stickers to send in the message
|
||||||
|
* @property {MessageFlags} [flags] Which flags to set for the message. Only `SUPPRESS_EMBEDS` can be set.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
6
packages/discord.js/typings/index.d.ts
vendored
6
packages/discord.js/typings/index.d.ts
vendored
@@ -3145,7 +3145,7 @@ export interface PartialWebhookFields {
|
|||||||
options: string | MessagePayload | WebhookEditMessageOptions,
|
options: string | MessagePayload | WebhookEditMessageOptions,
|
||||||
): Promise<Message | APIMessage>;
|
): Promise<Message | APIMessage>;
|
||||||
fetchMessage(message: Snowflake | '@original', options?: WebhookFetchMessageOptions): Promise<Message | APIMessage>;
|
fetchMessage(message: Snowflake | '@original', options?: WebhookFetchMessageOptions): Promise<Message | APIMessage>;
|
||||||
send(options: string | MessagePayload | WebhookMessageOptions): Promise<Message | APIMessage>;
|
send(options: string | MessagePayload | Omit<WebhookMessageOptions, 'flags'>): Promise<Message | APIMessage>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WebhookFields extends PartialWebhookFields {
|
export interface WebhookFields extends PartialWebhookFields {
|
||||||
@@ -4491,9 +4491,10 @@ export interface InteractionDeferReplyOptions {
|
|||||||
|
|
||||||
export type InteractionDeferUpdateOptions = Omit<InteractionDeferReplyOptions, 'ephemeral'>;
|
export type InteractionDeferUpdateOptions = Omit<InteractionDeferReplyOptions, 'ephemeral'>;
|
||||||
|
|
||||||
export interface InteractionReplyOptions extends Omit<WebhookMessageOptions, 'username' | 'avatarURL'> {
|
export interface InteractionReplyOptions extends Omit<WebhookMessageOptions, 'username' | 'avatarURL' | 'flags'> {
|
||||||
ephemeral?: boolean;
|
ephemeral?: boolean;
|
||||||
fetchReply?: boolean;
|
fetchReply?: boolean;
|
||||||
|
flags?: BitFieldResolvable<'SUPPRESS_EMBEDS' | 'EPHEMERAL', number>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InteractionUpdateOptions extends MessageEditOptions {
|
export interface InteractionUpdateOptions extends MessageEditOptions {
|
||||||
@@ -4693,6 +4694,7 @@ export interface MessageOptions {
|
|||||||
reply?: ReplyOptions;
|
reply?: ReplyOptions;
|
||||||
stickers?: StickerResolvable[];
|
stickers?: StickerResolvable[];
|
||||||
attachments?: MessageAttachment[];
|
attachments?: MessageAttachment[];
|
||||||
|
flags?: BitFieldResolvable<'SUPPRESS_EMBEDS', number>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MessageReactionResolvable =
|
export type MessageReactionResolvable =
|
||||||
|
|||||||
Reference in New Issue
Block a user