11import Bun from "bun" ;
22import { heapStats } from "bun:jsc" ;
33import {
4- ApplicationIntegrationType ,
4+ ApplicationCommandType ,
5+ AutocompleteInteraction ,
56 ChannelType ,
7+ ChatInputCommandInteraction ,
68 GuildMember ,
7- InteractionContextType ,
89 MessageFlags ,
10+ type ApplicationCommandOptionData ,
11+ type CacheType ,
912 type CommandInteraction ,
1013} from "discord.js" ;
1114import { PermissionFlagsBits } from "discord-api-types/v8" ;
@@ -32,13 +35,17 @@ import client from ".";
3235
3336interface Command {
3437 data : {
35- options : any [ ] ;
3638 name : string ;
3739 description : string ;
38- integration_types : ApplicationIntegrationType [ ] ;
39- contexts : InteractionContextType [ ] ;
40+ options ?: ApplicationCommandOptionData [ ] ;
41+ integration_types ?: number [ ] ;
42+ contexts ?: number [ ] ;
43+ type ?: ApplicationCommandType ;
4044 } ;
41- execute : ( interaction : CommandInteraction ) => Promise < void > ;
45+ execute : ( interaction : ChatInputCommandInteraction ) => Promise < void > ;
46+ autoComplete ?: (
47+ interaction : AutocompleteInteraction < CacheType > ,
48+ ) => Promise < any > ;
4249}
4350
4451const commands : Record < string , Command > = {
@@ -175,11 +182,12 @@ const commands: Record<string, Command> = {
175182 "Enter the YouTube channel ID or Twitch Streamer to track" ,
176183 type : 3 ,
177184 required : true ,
185+ autocomplete : true ,
178186 } ,
179187 {
180188 name : "updates_channel" ,
181189 description :
182- "Enter the Guild channel to recieve updates in." ,
190+ "Enter the Guild channel to receive updates in." ,
183191 type : 7 ,
184192 required : false ,
185193 } ,
@@ -207,6 +215,9 @@ const commands: Record<string, Command> = {
207215 interaction . channelId ;
208216 const guildId = interaction . guildId ;
209217
218+ // Log the autocomplete value
219+ console . log ( `Autocomplete value: ${ platformUserId } ` ) ;
220+
210221 // Checks if the platform is valid ig
211222 if ( targetPlatform != "youtube" && targetPlatform != "twitch" ) {
212223 await interaction . reply ( {
@@ -386,7 +397,7 @@ const commands: Record<string, Command> = {
386397 }
387398
388399 return ;
389- case "twitch" :
400+ case "twitch" : {
390401 // Check if the streamer exists by getting the ID
391402 const streamerId = await getStreamerId ( platformUserId ) ;
392403
@@ -461,11 +472,24 @@ const commands: Record<string, Command> = {
461472 }
462473
463474 return ;
475+ }
464476 default :
465477 console . error ( "This should never happen" ) ;
466478 break ;
467479 }
468480 } ,
481+ autoComplete : async ( interaction : AutocompleteInteraction ) => {
482+ try {
483+ const platform = interaction . options . get ( "platform" ) ?. value ;
484+ const query = interaction . options . get ( "user_id" ) ?. value ;
485+
486+ if ( ! query ) {
487+ return ;
488+ }
489+ } catch ( error ) {
490+ console . error ( error ) ;
491+ }
492+ } ,
469493 } ,
470494 untrack : {
471495 data : {
@@ -582,7 +606,7 @@ const commands: Record<string, Command> = {
582606 }
583607
584608 return ;
585- case "twitch" :
609+ case "twitch" : {
586610 // get the twitch id for the streamer
587611 const streamerId = await getStreamerId ( youtubeChannelId ) ;
588612
@@ -632,6 +656,7 @@ const commands: Record<string, Command> = {
632656 }
633657
634658 return ;
659+ }
635660 default :
636661 return ;
637662 }
0 commit comments