mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor(InteractionResponses)!: Remove ephemeral response option (#10564)
BREAKING CHANGE: MessagePayload#isInteraction no longer serves a purpose and has been removed. BREAKING CHANGE: InteractionDeferReplyOptions no longer accepts ephemeral. Use flags instead. BREAKING CHANGE: InteractionReplyOptions no longer accepts ephemeral. Use flags instead.
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const { Buffer } = require('node:buffer');
|
||||
const { lazy, isJSONEncodable } = require('@discordjs/util');
|
||||
const { isJSONEncodable } = require('@discordjs/util');
|
||||
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
||||
const { MessageFlags } = require('discord-api-types/v10');
|
||||
const ActionRowBuilder = require('./ActionRowBuilder');
|
||||
const { DiscordjsError, DiscordjsRangeError, ErrorCodes } = require('../errors');
|
||||
const { resolveFile } = require('../util/DataResolver');
|
||||
const MessageFlagsBitField = require('../util/MessageFlagsBitField');
|
||||
const { basename, verifyString, resolvePartialEmoji } = require('../util/Util');
|
||||
|
||||
const getBaseInteraction = lazy(() => require('./BaseInteraction'));
|
||||
|
||||
/**
|
||||
* Represents a message to be sent to the API.
|
||||
*/
|
||||
@@ -88,17 +85,6 @@ class MessagePayload {
|
||||
return this.target instanceof MessageManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the target is an {@link BaseInteraction} or an {@link InteractionWebhook}
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
*/
|
||||
get isInteraction() {
|
||||
const BaseInteraction = getBaseInteraction();
|
||||
const InteractionWebhook = require('./InteractionWebhook');
|
||||
return this.target instanceof BaseInteraction || this.target instanceof InteractionWebhook;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the content of this message.
|
||||
* @returns {?string}
|
||||
@@ -120,7 +106,6 @@ class MessagePayload {
|
||||
*/
|
||||
resolveBody() {
|
||||
if (this.body) return this;
|
||||
const isInteraction = this.isInteraction;
|
||||
const isWebhook = this.isWebhook;
|
||||
|
||||
const content = this.makeContent();
|
||||
@@ -175,10 +160,6 @@ class MessagePayload {
|
||||
: this.target.flags?.bitfield;
|
||||
}
|
||||
|
||||
if (isInteraction && this.options.ephemeral) {
|
||||
flags |= MessageFlags.Ephemeral;
|
||||
}
|
||||
|
||||
let allowedMentions =
|
||||
this.options.allowedMentions === undefined
|
||||
? this.target.client.options.allowedMentions
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
const { isJSONEncodable } = require('@discordjs/util');
|
||||
const { InteractionResponseType, MessageFlags, Routes, InteractionType } = require('discord-api-types/v10');
|
||||
const { DiscordjsError, ErrorCodes } = require('../../errors');
|
||||
const MessageFlagsBitField = require('../../util/MessageFlagsBitField');
|
||||
const InteractionCollector = require('../InteractionCollector');
|
||||
const InteractionResponse = require('../InteractionResponse');
|
||||
const MessagePayload = require('../MessagePayload');
|
||||
@@ -23,7 +22,8 @@ class InteractionResponses {
|
||||
/**
|
||||
* Options for deferring the reply to an {@link BaseInteraction}.
|
||||
* @typedef {Object} InteractionDeferReplyOptions
|
||||
* @property {boolean} [ephemeral] Whether the reply should be ephemeral
|
||||
* @property {MessageFlagsResolvable} [flags] Flags for the reply.
|
||||
* <info>Only `MessageFlags.Ephemeral` can be set.</info>
|
||||
* @property {boolean} [fetchReply] Whether to fetch the reply
|
||||
*/
|
||||
|
||||
@@ -37,9 +37,8 @@ class InteractionResponses {
|
||||
* Options for a reply to a {@link BaseInteraction}.
|
||||
* @typedef {BaseMessageOptionsWithPoll} InteractionReplyOptions
|
||||
* @property {boolean} [tts=false] Whether the message should be spoken aloud
|
||||
* @property {boolean} [ephemeral] Whether the reply should be ephemeral
|
||||
* @property {boolean} [fetchReply] Whether to fetch the reply
|
||||
* @property {MessageFlags} [flags] Which flags to set for the message.
|
||||
* @property {MessageFlagsResolvable} [flags] Which flags to set for the message.
|
||||
* <info>Only `MessageFlags.Ephemeral`, `MessageFlags.SuppressEmbeds`, and `MessageFlags.SuppressNotifications`
|
||||
* can be set.</info>
|
||||
*/
|
||||
@@ -61,24 +60,25 @@ class InteractionResponses {
|
||||
* .catch(console.error)
|
||||
* @example
|
||||
* // Defer to send an ephemeral reply later
|
||||
* interaction.deferReply({ ephemeral: true })
|
||||
* interaction.deferReply({ flags: MessageFlags.Ephemeral })
|
||||
* .then(console.log)
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async deferReply(options = {}) {
|
||||
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);
|
||||
this.ephemeral = options.ephemeral ?? false;
|
||||
|
||||
await this.client.rest.post(Routes.interactionCallback(this.id, this.token), {
|
||||
body: {
|
||||
type: InteractionResponseType.DeferredChannelMessageWithSource,
|
||||
data: {
|
||||
flags: options.ephemeral ? MessageFlags.Ephemeral : undefined,
|
||||
flags: options.flags,
|
||||
},
|
||||
},
|
||||
auth: false,
|
||||
});
|
||||
this.deferred = true;
|
||||
|
||||
this.deferred = true;
|
||||
this.ephemeral = Boolean(options.flags & MessageFlags.Ephemeral);
|
||||
return options.fetchReply ? this.fetchReply() : new InteractionResponse(this);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ class InteractionResponses {
|
||||
* // Create an ephemeral reply with an embed
|
||||
* const embed = new EmbedBuilder().setDescription('Pong!');
|
||||
*
|
||||
* interaction.reply({ embeds: [embed], ephemeral: true })
|
||||
* interaction.reply({ embeds: [embed], flags: MessageFlags.Ephemeral })
|
||||
* .then(() => console.log('Reply sent.'))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
@@ -109,8 +109,6 @@ class InteractionResponses {
|
||||
|
||||
const { body: data, files } = await messagePayload.resolveBody().resolveFiles();
|
||||
|
||||
this.ephemeral = new MessageFlagsBitField(data.flags).has(MessageFlags.Ephemeral);
|
||||
|
||||
await this.client.rest.post(Routes.interactionCallback(this.id, this.token), {
|
||||
body: {
|
||||
type: InteractionResponseType.ChannelMessageWithSource,
|
||||
@@ -119,8 +117,9 @@ class InteractionResponses {
|
||||
files,
|
||||
auth: false,
|
||||
});
|
||||
this.replied = true;
|
||||
|
||||
this.ephemeral = Boolean(options.flags & MessageFlags.Ephemeral);
|
||||
this.replied = true;
|
||||
return options.fetchReply ? this.fetchReply() : new InteractionResponse(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,15 @@ class MessageFlagsBitField extends BitField {
|
||||
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
|
||||
*/
|
||||
|
||||
/**
|
||||
* Data that can be resolved to give a message flags bit field. This can be:
|
||||
* * A string (see {@link MessageFlagsBitField.Flags})
|
||||
* * A message flag
|
||||
* * An instance of {@link MessageFlagsBitField}
|
||||
* * An array of `MessageFlagsResolvable`
|
||||
* @typedef {string|number|MessageFlagsBitField|MessageFlagsResolvable[]} MessageFlagsResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Bitfield of the packed bits
|
||||
* @type {number}
|
||||
|
||||
11
packages/discord.js/typings/index.d.ts
vendored
11
packages/discord.js/typings/index.d.ts
vendored
@@ -2398,7 +2398,6 @@ export class MessagePayload {
|
||||
public get isWebhook(): boolean;
|
||||
public get isMessage(): boolean;
|
||||
public get isMessageManager(): boolean;
|
||||
public get isInteraction(): boolean;
|
||||
public files: RawFile[] | null;
|
||||
public options: MessagePayloadOption;
|
||||
public target: MessageTarget;
|
||||
@@ -6066,15 +6065,19 @@ export interface InteractionCollectorOptions<
|
||||
}
|
||||
|
||||
export interface InteractionDeferReplyOptions {
|
||||
ephemeral?: boolean;
|
||||
flags?: BitFieldResolvable<
|
||||
Extract<MessageFlagsString, 'Ephemeral' | 'SuppressEmbeds' | 'SuppressNotifications'>,
|
||||
MessageFlags.Ephemeral | MessageFlags.SuppressEmbeds | MessageFlags.SuppressNotifications
|
||||
>;
|
||||
fetchReply?: boolean;
|
||||
}
|
||||
|
||||
export interface InteractionDeferUpdateOptions extends Omit<InteractionDeferReplyOptions, 'ephemeral'> {}
|
||||
export interface InteractionDeferUpdateOptions {
|
||||
fetchReply?: boolean;
|
||||
}
|
||||
|
||||
export interface InteractionReplyOptions extends BaseMessageOptionsWithPoll {
|
||||
tts?: boolean;
|
||||
ephemeral?: boolean;
|
||||
fetchReply?: boolean;
|
||||
flags?: BitFieldResolvable<
|
||||
Extract<MessageFlagsString, 'Ephemeral' | 'SuppressEmbeds' | 'SuppressNotifications'>,
|
||||
|
||||
Reference in New Issue
Block a user