@@ -31,14 +31,14 @@ export default function registerEvents(client: Client) {
31
31
// Register events for the actual walkthrough steps
32
32
client . on ( Events . InteractionCreate , async ( interaction ) => {
33
33
if ( interaction . isStringSelectMenu ( ) ) {
34
- let message : InteractionUpdateOptions ;
34
+ let messageData : InteractionUpdateOptions ;
35
35
36
36
const selector = selectors . filter (
37
37
( element ) => element . data . custom_id === interaction . customId ,
38
38
) [ 0 ] ;
39
39
const index = selectors . indexOf ( selector ) ;
40
40
41
- const nextSelector = selectors [ index + 1 ] ;
41
+ const lastStep = index + 1 === selectors . length ;
42
42
43
43
if ( index === 0 ) {
44
44
const dataEmbed = new EmbedBuilder ( )
@@ -57,7 +57,7 @@ export default function registerEvents(client: Client) {
57
57
} ,
58
58
] ) ;
59
59
60
- message = generateQuestion (
60
+ messageData = generateQuestion (
61
61
"What product are you using?" ,
62
62
productSelector ,
63
63
[ dataEmbed ] ,
@@ -72,23 +72,25 @@ export default function registerEvents(client: Client) {
72
72
73
73
// TODO : make this part more generic once we have more questions
74
74
if ( selector === productSelector ) {
75
- message = generateQuestion (
75
+ messageData = generateQuestion (
76
76
`What operating system are you running ${ dataEmbed . fields [ index ] . value } on?` ,
77
- nextSelector ,
77
+ selectors [ index + 1 ] , // next selector
78
78
[ dataEmbed ] ,
79
79
) ;
80
- } else if ( index + 1 === selectors . length ) {
81
- // <- means this is the last step of the walkthrough
82
- // Generate an empty message with just the data embed and pin it
83
- message = { components : [ ] , embeds : [ dataEmbed ] } ;
84
-
85
- await interaction . message . pin ( ) ;
80
+ } else if ( lastStep ) {
81
+ // This is the last step of the walkthrough, so we generate an empty message with just the data embed
82
+ messageData = { components : [ ] , embeds : [ dataEmbed ] } ;
86
83
} else {
87
84
throw new Error ( "No case matches this walkthrough step" ) ;
88
85
}
89
86
}
90
87
91
- await interaction . update ( message ) ;
88
+ await interaction . update ( messageData ) ;
89
+
90
+ // If this is the last step of the walkthrough, we pin the message
91
+ if ( lastStep ) {
92
+ await interaction . message . pin ( ) ;
93
+ }
92
94
}
93
95
} ) ;
94
96
}
0 commit comments