3
3
const { isJSONEncodable } = require ( '@discordjs/util' ) ;
4
4
const { InteractionResponseType, MessageFlags, Routes, InteractionType } = require ( 'discord-api-types/v10' ) ;
5
5
const { DiscordjsError, ErrorCodes } = require ( '../../errors' ) ;
6
- const MessageFlagsBitField = require ( '../../util/MessageFlagsBitField' ) ;
7
6
const InteractionCollector = require ( '../InteractionCollector' ) ;
8
7
const InteractionResponse = require ( '../InteractionResponse' ) ;
9
8
const MessagePayload = require ( '../MessagePayload' ) ;
@@ -23,7 +22,8 @@ class InteractionResponses {
23
22
/**
24
23
* Options for deferring the reply to an {@link BaseInteraction}.
25
24
* @typedef {Object } InteractionDeferReplyOptions
26
- * @property {boolean } [ephemeral] Whether the reply should be ephemeral
25
+ * @property {MessageFlagsResolvable } [flags] Flags for the reply.
26
+ * <info>Only `MessageFlags.Ephemeral` can be set.</info>
27
27
* @property {boolean } [fetchReply] Whether to fetch the reply
28
28
*/
29
29
@@ -37,9 +37,8 @@ class InteractionResponses {
37
37
* Options for a reply to a {@link BaseInteraction}.
38
38
* @typedef {BaseMessageOptionsWithPoll } InteractionReplyOptions
39
39
* @property {boolean } [tts=false] Whether the message should be spoken aloud
40
- * @property {boolean } [ephemeral] Whether the reply should be ephemeral
41
40
* @property {boolean } [fetchReply] Whether to fetch the reply
42
- * @property {MessageFlags } [flags] Which flags to set for the message.
41
+ * @property {MessageFlagsResolvable } [flags] Which flags to set for the message.
43
42
* <info>Only `MessageFlags.Ephemeral`, `MessageFlags.SuppressEmbeds`, and `MessageFlags.SuppressNotifications`
44
43
* can be set.</info>
45
44
*/
@@ -61,24 +60,25 @@ class InteractionResponses {
61
60
* .catch(console.error)
62
61
* @example
63
62
* // Defer to send an ephemeral reply later
64
- * interaction.deferReply({ ephemeral: true })
63
+ * interaction.deferReply({ flags: MessageFlags.Ephemeral })
65
64
* .then(console.log)
66
65
* .catch(console.error);
67
66
*/
68
67
async deferReply ( options = { } ) {
69
68
if ( this . deferred || this . replied ) throw new DiscordjsError ( ErrorCodes . InteractionAlreadyReplied ) ;
70
- this . ephemeral = options . ephemeral ?? false ;
69
+
71
70
await this . client . rest . post ( Routes . interactionCallback ( this . id , this . token ) , {
72
71
body : {
73
72
type : InteractionResponseType . DeferredChannelMessageWithSource ,
74
73
data : {
75
- flags : options . ephemeral ? MessageFlags . Ephemeral : undefined ,
74
+ flags : options . flags ,
76
75
} ,
77
76
} ,
78
77
auth : false ,
79
78
} ) ;
80
- this . deferred = true ;
81
79
80
+ this . deferred = true ;
81
+ this . ephemeral = Boolean ( options . flags & MessageFlags . Ephemeral ) ;
82
82
return options . fetchReply ? this . fetchReply ( ) : new InteractionResponse ( this ) ;
83
83
}
84
84
@@ -96,7 +96,7 @@ class InteractionResponses {
96
96
* // Create an ephemeral reply with an embed
97
97
* const embed = new EmbedBuilder().setDescription('Pong!');
98
98
*
99
- * interaction.reply({ embeds: [embed], ephemeral: true })
99
+ * interaction.reply({ embeds: [embed], flags: MessageFlags.Ephemeral })
100
100
* .then(() => console.log('Reply sent.'))
101
101
* .catch(console.error);
102
102
*/
@@ -109,8 +109,6 @@ class InteractionResponses {
109
109
110
110
const { body : data , files } = await messagePayload . resolveBody ( ) . resolveFiles ( ) ;
111
111
112
- this . ephemeral = new MessageFlagsBitField ( data . flags ) . has ( MessageFlags . Ephemeral ) ;
113
-
114
112
await this . client . rest . post ( Routes . interactionCallback ( this . id , this . token ) , {
115
113
body : {
116
114
type : InteractionResponseType . ChannelMessageWithSource ,
@@ -119,8 +117,9 @@ class InteractionResponses {
119
117
files,
120
118
auth : false ,
121
119
} ) ;
122
- this . replied = true ;
123
120
121
+ this . ephemeral = Boolean ( options . flags & MessageFlags . Ephemeral ) ;
122
+ this . replied = true ;
124
123
return options . fetchReply ? this . fetchReply ( ) : new InteractionResponse ( this ) ;
125
124
}
126
125
0 commit comments