@@ -13,6 +13,7 @@ import {
1313 Colors ,
1414 type PublicThreadChannel ,
1515 type GuildTextBasedChannel ,
16+ FetchMessageOptions ,
1617} from "discord.js" ;
1718
1819export function generateMessage (
@@ -50,8 +51,28 @@ export async function doWalkthrough(
5051 ) ;
5152
5253 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+ }
5576 } else {
5677 return channel . send ( message ) ;
5778 }
@@ -70,6 +91,6 @@ export default {
7091 interaction . channelId ,
7192 ) ) as GuildTextBasedChannel ;
7293
73- return doWalkthrough ( interactionChannel ) ;
94+ return doWalkthrough ( interactionChannel , interaction ) ;
7495 } ,
7596} ;
0 commit comments