1- import { Message , EmbedBuilder , ActionRowBuilder , StringSelectMenuBuilder , ButtonBuilder , ButtonStyle , ComponentType , BaseInteraction } from 'discord.js'
1+ import { EmbedBuilder , ActionRowBuilder , StringSelectMenuBuilder , ButtonBuilder , ButtonStyle , ComponentType , BaseInteraction , CommandInteraction } from 'discord.js'
22import axios from 'axios'
33import { responseHandler } from '../../utils/responseHandler.js'
44import { dateUtils } from '../../utils/dateUtils.js'
@@ -7,21 +7,28 @@ import { fetchMembers } from './GuildMembers.js'
77import { fetchStore } from './GuildStore.js'
88import { fetchShouts } from './GuildShouts.js'
99
10- export async function guild ( message : Message , args : string [ ] ) : Promise < Message | null > {
11- const guildID : number = parseInt ( args [ 0 ] )
10+ export async function guild ( interaction :CommandInteraction ) {
11+ // @ts -expect-error
12+ const guildID = interaction . options . getInteger ( 'id' )
1213
13- if ( args . length === 0 ) {
14- return message . reply ( 'Please provide me with a guild ID before I can continue!' )
14+ if ( guildID . length === 0 ) {
15+ return await interaction . reply ( 'Please provide me with a guild ID before I can continue!' )
1516 }
1617
18+ await interaction . deferReply ( )
19+
1720 const response = await axios . get ( `https://api.polytoria.com/v1/guilds/${ guildID } ` , { validateStatus : ( ) => true } )
1821 const data = response . data
1922 const creator = data . creator
2023
2124 const errResult = responseHandler . checkError ( response )
2225
2326 if ( errResult . hasError === true ) {
24- return message . channel . send ( errResult . displayText )
27+ if ( errResult . statusCode === 404 ) {
28+ return await interaction . editReply ( "Couldn't find the requested guild. Did you type in the correct guild ID?" )
29+ } else {
30+ return await interaction . editReply ( errResult . displayText )
31+ }
2532 }
2633
2734 let joinType ! : string
@@ -129,7 +136,7 @@ export async function guild (message: Message, args: string[]): Promise<Message
129136 const actionRow = new ActionRowBuilder < StringSelectMenuBuilder > ( )
130137 . addComponents ( dropdown )
131138
132- const reply = await message . reply ( {
139+ const reply = await interaction . editReply ( {
133140 embeds : [ embed ] ,
134141 components : [ actionRow ]
135142 } )
@@ -142,17 +149,17 @@ export async function guild (message: Message, args: string[]): Promise<Message
142149
143150 const collector = reply . createMessageComponentCollector ( {
144151 componentType : ComponentType . SelectMenu ,
145- filter : ( interaction : BaseInteraction ) => (
146- interaction . isStringSelectMenu ( ) && interaction . customId === 'dropdown_menu' &&
147- interaction . user . id === message . author . id
152+ filter : ( messageInteraction : BaseInteraction ) => (
153+ messageInteraction . isStringSelectMenu ( ) && messageInteraction . customId === 'dropdown_menu' &&
154+ messageInteraction . user . id === interaction . user . id
148155 ) ,
149156 time : 60000
150157 } )
151158
152- collector . on ( 'collect' , async ( interaction ) => {
153- await interaction . deferUpdate ( )
159+ collector . on ( 'collect' , async ( messageInteraction ) => {
160+ await messageInteraction . deferUpdate ( )
154161
155- selectedOption = interaction . values [ 0 ]
162+ selectedOption = messageInteraction . values [ 0 ]
156163
157164 if ( selectedOption === 'guild_option' ) {
158165 await interaction . editReply ( {
@@ -200,14 +207,14 @@ export async function guild (message: Message, args: string[]): Promise<Message
200207 filter : ( btnInteraction : BaseInteraction ) => (
201208 btnInteraction . isButton ( ) &&
202209 btnInteraction . customId === 'prev_button' &&
203- btnInteraction . user . id === message . author . id
210+ btnInteraction . user . id === interaction . user . id
204211 ) ,
205212 time : 60000
206213 } )
207214
208- prevButtonCollector . on ( 'collect' , async ( interaction ) => {
215+ prevButtonCollector . on ( 'collect' , async ( buttonInteraction ) => {
209216 try {
210- await interaction . deferUpdate ( )
217+ await buttonInteraction . deferUpdate ( )
211218
212219 if ( selectedOption === 'members_option' && memberPage > 1 ) {
213220 memberPage --
@@ -258,14 +265,14 @@ export async function guild (message: Message, args: string[]): Promise<Message
258265 filter : ( btnInteraction : BaseInteraction ) => (
259266 btnInteraction . isButton ( ) &&
260267 btnInteraction . customId === 'next_button' &&
261- btnInteraction . user . id === message . author . id
268+ btnInteraction . user . id === interaction . user . id
262269 ) ,
263270 time : 60000
264271 } )
265272
266- nextButtonCollector . on ( 'collect' , async ( interaction ) => {
273+ nextButtonCollector . on ( 'collect' , async ( buttonInteraction ) => {
267274 try {
268- await interaction . deferUpdate ( )
275+ await buttonInteraction . deferUpdate ( )
269276
270277 if ( selectedOption === 'members_option' ) {
271278 memberPage ++
@@ -310,6 +317,4 @@ export async function guild (message: Message, args: string[]): Promise<Message
310317 console . error ( 'Error handling interaction:' , error )
311318 }
312319 } )
313-
314- return reply
315320}
0 commit comments