Skip to content

Commit

Permalink
fix(InteractionResponses): properly resolve message flags (#10661)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdanialraza authored Dec 18, 2024
1 parent 53cbb0e commit b2754d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
9 changes: 3 additions & 6 deletions packages/discord.js/src/structures/MessagePayload.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,12 @@ class MessagePayload {

let flags;
if (
this.options.flags !== undefined ||
// eslint-disable-next-line eqeqeq
this.options.flags != null ||
(this.isMessage && this.options.reply === undefined) ||
this.isMessageManager
) {
flags =
// eslint-disable-next-line eqeqeq
this.options.flags != null
? new MessageFlagsBitField(this.options.flags).bitfield
: this.target.flags?.bitfield;
flags = new MessageFlagsBitField(this.options.flags).bitfield;
}

if (isInteraction && this.options.ephemeral) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { deprecate } = require('node:util');
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');
Expand Down Expand Up @@ -85,24 +86,25 @@ class InteractionResponses {
}
}

let { flags } = options;
const flags = new MessageFlagsBitField(options.flags);

if (options.ephemeral) {
flags |= MessageFlags.Ephemeral;
flags.add(MessageFlags.Ephemeral);
}

await this.client.rest.post(Routes.interactionCallback(this.id, this.token), {
body: {
type: InteractionResponseType.DeferredChannelMessageWithSource,
data: {
flags,
flags: flags.bitfield,
},
},
auth: false,
});

this.deferred = true;
this.ephemeral = Boolean(flags & MessageFlags.Ephemeral);
this.ephemeral = flags.has(MessageFlags.Ephemeral);

return options.fetchReply ? this.fetchReply() : new InteractionResponse(this);
}

Expand Down Expand Up @@ -154,6 +156,7 @@ class InteractionResponses {

this.ephemeral = Boolean(data.flags & MessageFlags.Ephemeral);
this.replied = true;

return options.fetchReply ? this.fetchReply() : new InteractionResponse(this);
}

Expand Down

0 comments on commit b2754d4

Please sign in to comment.