@@ -13,6 +13,7 @@ import {
13
13
Colors ,
14
14
type PublicThreadChannel ,
15
15
type GuildTextBasedChannel ,
16
+ FetchMessageOptions ,
16
17
} from "discord.js" ;
17
18
18
19
export function generateMessage (
@@ -50,8 +51,28 @@ export async function doWalkthrough(
50
51
) ;
51
52
52
53
if ( interaction ) {
53
- // TODO: check if walkthrough has already been sent
54
- return interaction . reply ( message ) ;
54
+ // If the bot has sent a message that contains an embed in the first 30 messages, then we assume it's the walkthrough message
55
+ const firstMessage = await threadChannel . fetchStarterMessage ( ) ;
56
+ const walkthroughMessage = await threadChannel . messages
57
+ . fetch ( { around : firstMessage . id , limit : 30 } )
58
+ . then ( ( messages ) =>
59
+ messages
60
+ . filter (
61
+ ( message ) =>
62
+ message . author . id === interaction . client . user . id &&
63
+ message . embeds . length > 0 ,
64
+ )
65
+ . at ( 0 ) ,
66
+ ) ;
67
+
68
+ if ( walkthroughMessage ) {
69
+ await interaction . reply ( {
70
+ content : `You cannot run the walkthrough command because a walkthrough already exists in this channel.\n(${ walkthroughMessage . url } )` ,
71
+ ephemeral : true ,
72
+ } ) ;
73
+ } else {
74
+ return interaction . reply ( message ) ;
75
+ }
55
76
} else {
56
77
return channel . send ( message ) ;
57
78
}
@@ -70,6 +91,6 @@ export default {
70
91
interaction . channelId ,
71
92
) ) as GuildTextBasedChannel ;
72
93
73
- return doWalkthrough ( interactionChannel ) ;
94
+ return doWalkthrough ( interactionChannel , interaction ) ;
74
95
} ,
75
96
} ;
0 commit comments