@@ -31,14 +31,14 @@ export default function registerEvents(client: Client) {
3131 // Register events for the actual walkthrough steps
3232 client . on ( Events . InteractionCreate , async ( interaction ) => {
3333 if ( interaction . isStringSelectMenu ( ) ) {
34- let message : InteractionUpdateOptions ;
34+ let messageData : InteractionUpdateOptions ;
3535
3636 const selector = selectors . filter (
3737 ( element ) => element . data . custom_id === interaction . customId ,
3838 ) [ 0 ] ;
3939 const index = selectors . indexOf ( selector ) ;
4040
41- const nextSelector = selectors [ index + 1 ] ;
41+ const lastStep = index + 1 === selectors . length ;
4242
4343 if ( index === 0 ) {
4444 const dataEmbed = new EmbedBuilder ( )
@@ -57,7 +57,7 @@ export default function registerEvents(client: Client) {
5757 } ,
5858 ] ) ;
5959
60- message = generateQuestion (
60+ messageData = generateQuestion (
6161 "What product are you using?" ,
6262 productSelector ,
6363 [ dataEmbed ] ,
@@ -72,23 +72,25 @@ export default function registerEvents(client: Client) {
7272
7373 // TODO : make this part more generic once we have more questions
7474 if ( selector === productSelector ) {
75- message = generateQuestion (
75+ messageData = generateQuestion (
7676 `What operating system are you running ${ dataEmbed . fields [ index ] . value } on?` ,
77- nextSelector ,
77+ selectors [ index + 1 ] , // next selector
7878 [ dataEmbed ] ,
7979 ) ;
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 ] } ;
8683 } else {
8784 throw new Error ( "No case matches this walkthrough step" ) ;
8885 }
8986 }
9087
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+ }
9294 }
9395 } ) ;
9496}
0 commit comments