@@ -8,10 +8,11 @@ import {
88 PermissionFlagsBits ,
99 type APIChatInputApplicationCommandGuildInteraction ,
1010 type RESTPostAPIApplicationCommandsJSONBody ,
11- } from '@discordjs/core' ;
11+ } from '@discordjs/core/http-only' ;
12+ import type { API } from '@discordjs/core/http-only' ;
1213import { InteractionOptionResolver } from '@sapphire/discord-utilities' ;
1314import { PermissionsBitField } from '../permissions.js' ;
14- import { api , ENV , logger } from '../util.js' ;
15+ import { logger , type Env } from '../util.js' ;
1516
1617export const interaction : RESTPostAPIApplicationCommandsJSONBody = {
1718 name : 'setup' ,
@@ -42,9 +43,9 @@ export const interaction: RESTPostAPIApplicationCommandsJSONBody = {
4243 integration_types : [ ApplicationIntegrationType . GuildInstall ] ,
4344} ;
4445
45- export async function handle ( interaction : APIChatInputApplicationCommandGuildInteraction ) {
46+ export async function handle ( interaction : APIChatInputApplicationCommandGuildInteraction , env : Env , api : API ) {
4647 if ( ! PermissionsBitField . has ( BigInt ( interaction . app_permissions ) , PermissionFlagsBits . ManageWebhooks ) ) {
47- return api . interactions . editReply ( ENV . CLIENT_ID , interaction . token , {
48+ return api . interactions . editReply ( env . CLIENT_ID , interaction . token , {
4849 content : 'The bot does not have the required permissions to set up the webhook.' ,
4950 } ) ;
5051 }
@@ -54,11 +55,11 @@ export async function handle(interaction: APIChatInputApplicationCommandGuildInt
5455 switch ( options . getSubcommand ( true ) ) {
5556 case 'webhook' : {
5657 const webhooks = await api . channels . getWebhooks ( interaction . channel . id ) ;
57- const webhook = webhooks . find ( ( webhook ) => webhook . user ! . id === ENV . CLIENT_ID ) ;
58+ const webhook = webhooks . find ( ( webhook ) => webhook . user ! . id === env . CLIENT_ID ) ;
5859 if ( webhook ) {
5960 logger . debug ( 'found existing webhook' ) ;
6061 const fullWebhook = await api . webhooks . get ( webhook . id ) ;
61- return api . interactions . editReply ( ENV . CLIENT_ID , interaction . token , {
62+ return api . interactions . editReply ( env . CLIENT_ID , interaction . token , {
6263 content : `Here's the webhook url: https://discord.com/api/webhooks/${ fullWebhook . id } /${ fullWebhook . token ! } ` ,
6364 } ) ;
6465 }
@@ -68,7 +69,7 @@ export async function handle(interaction: APIChatInputApplicationCommandGuildInt
6869 name : 'Prompt' ,
6970 } ) ;
7071
71- return api . interactions . editReply ( ENV . CLIENT_ID , interaction . token , {
72+ return api . interactions . editReply ( env . CLIENT_ID , interaction . token , {
7273 content : `Here's the webhook url: https://discord.com/api/webhooks/${ newWebhook . id } /${ newWebhook . token ! } ` ,
7374 } ) ;
7475 }
@@ -77,21 +78,21 @@ export async function handle(interaction: APIChatInputApplicationCommandGuildInt
7778 const messageURL = options . getString ( 'message' , true ) ;
7879 const [ channelId , messageId ] = messageURL . split ( '/' ) . slice ( - 2 ) as [ string , string ] ;
7980 if ( ! channelId || ! messageId ) {
80- return api . interactions . editReply ( ENV . CLIENT_ID , interaction . token , {
81+ return api . interactions . editReply ( env . CLIENT_ID , interaction . token , {
8182 content : 'Invalid message URL' ,
8283 } ) ;
8384 }
8485
8586 const message = await api . channels . getMessage ( channelId , messageId ) . catch ( ( ) => null ) ;
8687 if ( ! message ) {
87- return api . interactions . editReply ( ENV . CLIENT_ID , interaction . token , {
88+ return api . interactions . editReply ( env . CLIENT_ID , interaction . token , {
8889 content : 'Message not found' ,
8990 } ) ;
9091 }
9192
9293 const webhook = message . webhook_id ? await api . webhooks . get ( message . webhook_id ) . catch ( ( ) => null ) : null ;
93- if ( ! webhook || webhook . user ! . id !== ENV . CLIENT_ID ) {
94- return api . interactions . editReply ( ENV . CLIENT_ID , interaction . token , {
94+ if ( ! webhook || webhook . user ! . id !== env . CLIENT_ID ) {
95+ return api . interactions . editReply ( env . CLIENT_ID , interaction . token , {
9596 content : 'Message does not belong to bot webhook' ,
9697 } ) ;
9798 }
@@ -111,7 +112,7 @@ export async function handle(interaction: APIChatInputApplicationCommandGuildInt
111112 } ,
112113 ] ,
113114 } ) ;
114- await api . interactions . editReply ( ENV . CLIENT_ID , interaction . token , {
115+ await api . interactions . editReply ( env . CLIENT_ID , interaction . token , {
115116 content : 'Prompt added to the message' ,
116117 } ) ;
117118
0 commit comments