@@ -47,8 +47,14 @@ app.post('/interactions', verifyKeyMiddleware(process.env.PUBLIC_KEY), async fun
47
47
return res . send ( {
48
48
type : InteractionResponseType . CHANNEL_MESSAGE_WITH_SOURCE ,
49
49
data : {
50
- // Fetches a random emoji to send from a helper function
51
- content : `hello world ${ getRandomEmoji ( ) } ` ,
50
+ flags : InteractionResponseFlags . IS_COMPONENTS_V2 ,
51
+ components : [
52
+ {
53
+ type : MessageComponentTypes . TEXT_DISPLAY ,
54
+ // Fetches a random emoji to send from a helper function
55
+ content : `hello world ${ getRandomEmoji ( ) } `
56
+ }
57
+ ]
52
58
} ,
53
59
} ) ;
54
60
}
@@ -71,9 +77,13 @@ app.post('/interactions', verifyKeyMiddleware(process.env.PUBLIC_KEY), async fun
71
77
return res . send ( {
72
78
type : InteractionResponseType . CHANNEL_MESSAGE_WITH_SOURCE ,
73
79
data : {
74
- // Fetches a random emoji to send from a helper function
75
- content : `Rock papers scissors challenge from <@${ userId } >` ,
80
+ flags : InteractionResponseFlags . IS_COMPONENTS_V2 ,
76
81
components : [
82
+ {
83
+ type : MessageComponentTypes . TEXT_DISPLAY ,
84
+ // Fetches a random emoji to send from a helper function
85
+ content : `Rock papers scissors challenge from <@${ userId } >` ,
86
+ } ,
77
87
{
78
88
type : MessageComponentTypes . ACTION_ROW ,
79
89
components : [
@@ -97,7 +107,7 @@ app.post('/interactions', verifyKeyMiddleware(process.env.PUBLIC_KEY), async fun
97
107
98
108
/**
99
109
* Handle requests from interactive components
100
- * See https://discord.com/developers/docs/interactions/ message-components#responding-to-a-component-interaction
110
+ * See https://discord.com/developers/docs/components/using- message-components#using-message-components-with-interactions
101
111
*/
102
112
if ( type === InteractionType . MESSAGE_COMPONENT ) {
103
113
// custom_id set in payload when sending message component
@@ -112,10 +122,13 @@ app.post('/interactions', verifyKeyMiddleware(process.env.PUBLIC_KEY), async fun
112
122
await res . send ( {
113
123
type : InteractionResponseType . CHANNEL_MESSAGE_WITH_SOURCE ,
114
124
data : {
115
- content : 'What is your object of choice?' ,
116
125
// Indicates it'll be an ephemeral message
117
- flags : InteractionResponseFlags . EPHEMERAL ,
126
+ flags : InteractionResponseFlags . EPHEMERAL | InteractionResponseFlags . IS_COMPONENTS_V2 ,
118
127
components : [
128
+ {
129
+ type : MessageComponentTypes . TEXT_DISPLAY ,
130
+ content : 'What is your object of choice?' ,
131
+ } ,
119
132
{
120
133
type : MessageComponentTypes . ACTION_ROW ,
121
134
components : [
@@ -161,14 +174,26 @@ app.post('/interactions', verifyKeyMiddleware(process.env.PUBLIC_KEY), async fun
161
174
// Send results
162
175
await res . send ( {
163
176
type : InteractionResponseType . CHANNEL_MESSAGE_WITH_SOURCE ,
164
- data : { content : resultStr } ,
177
+ data : {
178
+ flags : InteractionResponseFlags . IS_COMPONENTS_V2 ,
179
+ components : [
180
+ {
181
+ type : MessageComponentTypes . TEXT_DISPLAY ,
182
+ content : resultStr
183
+ }
184
+ ]
185
+ } ,
165
186
} ) ;
166
187
// Update ephemeral message
167
188
await DiscordRequest ( endpoint , {
168
189
method : 'PATCH' ,
169
190
body : {
170
- content : 'Nice choice ' + getRandomEmoji ( ) ,
171
- components : [ ] ,
191
+ components : [
192
+ {
193
+ type : MessageComponentTypes . TEXT_DISPLAY ,
194
+ content : 'Nice choice ' + getRandomEmoji ( )
195
+ }
196
+ ] ,
172
197
} ,
173
198
} ) ;
174
199
} catch ( err ) {
0 commit comments