fix(InteractionResponses): properly resolve message flags (#10660)

This commit is contained in:
Danial Raza
2024-12-18 15:39:04 +01:00
committed by GitHub
parent 35ebcc7d5a
commit f1bce54a28
2 changed files with 9 additions and 9 deletions

View File

@@ -149,15 +149,12 @@ class MessagePayload {
let flags; let flags;
if ( if (
this.options.flags !== undefined || // eslint-disable-next-line eqeqeq
this.options.flags != null ||
(this.isMessage && this.options.reply === undefined) || (this.isMessage && this.options.reply === undefined) ||
this.isMessageManager this.isMessageManager
) { ) {
flags = flags = new MessageFlagsBitField(this.options.flags).bitfield;
// eslint-disable-next-line eqeqeq
this.options.flags != null
? new MessageFlagsBitField(this.options.flags).bitfield
: this.target.flags?.bitfield;
} }
let allowedMentions = let allowedMentions =

View File

@@ -4,6 +4,7 @@ const { makeURLSearchParams } = require('@discordjs/rest');
const { isJSONEncodable } = require('@discordjs/util'); const { isJSONEncodable } = require('@discordjs/util');
const { InteractionResponseType, MessageFlags, Routes, InteractionType } = require('discord-api-types/v10'); const { InteractionResponseType, MessageFlags, Routes, InteractionType } = require('discord-api-types/v10');
const { DiscordjsError, ErrorCodes } = require('../../errors'); const { DiscordjsError, ErrorCodes } = require('../../errors');
const MessageFlagsBitField = require('../../util/MessageFlagsBitField');
const InteractionCallbackResponse = require('../InteractionCallbackResponse'); const InteractionCallbackResponse = require('../InteractionCallbackResponse');
const InteractionCollector = require('../InteractionCollector'); const InteractionCollector = require('../InteractionCollector');
const InteractionResponse = require('../InteractionResponse'); const InteractionResponse = require('../InteractionResponse');
@@ -75,11 +76,13 @@ class InteractionResponses {
async deferReply(options = {}) { async deferReply(options = {}) {
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied); if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);
const resolvedFlags = new MessageFlagsBitField(options.flags);
const response = await this.client.rest.post(Routes.interactionCallback(this.id, this.token), { const response = await this.client.rest.post(Routes.interactionCallback(this.id, this.token), {
body: { body: {
type: InteractionResponseType.DeferredChannelMessageWithSource, type: InteractionResponseType.DeferredChannelMessageWithSource,
data: { data: {
flags: options.flags, flags: resolvedFlags.bitfield,
}, },
}, },
auth: false, auth: false,
@@ -87,7 +90,7 @@ class InteractionResponses {
}); });
this.deferred = true; this.deferred = true;
this.ephemeral = Boolean(options.flags & MessageFlags.Ephemeral); this.ephemeral = resolvedFlags.has(MessageFlags.Ephemeral);
return options.withResponse return options.withResponse
? new InteractionCallbackResponse(this.client, response) ? new InteractionCallbackResponse(this.client, response)
@@ -131,7 +134,7 @@ class InteractionResponses {
query: makeURLSearchParams({ with_response: options.withResponse ?? false }), query: makeURLSearchParams({ with_response: options.withResponse ?? false }),
}); });
this.ephemeral = Boolean(options.flags & MessageFlags.Ephemeral); this.ephemeral = Boolean(data.flags & MessageFlags.Ephemeral);
this.replied = true; this.replied = true;
return options.withResponse return options.withResponse