1- import { MessageActionRow , MessageSelectMenu } from 'discord.js' ;
2- import type { Message , TextChannel } from 'discord.js' ;
1+ import { ActionRowBuilder , ChannelType , EmbedBuilder , MessageActionRowComponentBuilder , StringSelectMenuBuilder , } from 'discord.js' ;
2+ import { ComponentType , Message , TextChannel } from 'discord.js' ;
33import type { Client } from 'discord.js' ;
44
55import { POINT_LIMITER_IN_MINUTES } from '../../env.js' ;
@@ -41,7 +41,7 @@ const handleThanks = async (msg: Message): Promise<void> => {
4141 const reply = await getReply ( msg ) ;
4242 if ( botId || ( msg . mentions . users . size === 0 && ! reply ) ) {
4343 if (
44- [ 'GUILD_PRIVATE_THREAD' , 'GUILD_PUBLIC_THREAD' ] . includes ( msg . channel . type )
44+ [ ChannelType . PrivateThread , ChannelType . PublicThread ] . includes ( msg . channel . type )
4545 ) {
4646 await handleThreadThanks ( msg ) ;
4747 }
@@ -118,9 +118,8 @@ const handleThanks = async (msg: Message): Promise<void> => {
118118 value : `<@!${ u . id } >\n${ diff } minute${ diff === 1 ? '' : 's' } .` ,
119119 } ;
120120 } ) ,
121- footerText : `You can only give a point to a user every ${ POINT_LIMITER_IN_MINUTES } minute${
122- Number . parseInt ( POINT_LIMITER_IN_MINUTES ) === 1 ? '' : 's'
123- } .`,
121+ footerText : `You can only give a point to a user every ${ POINT_LIMITER_IN_MINUTES } minute${ Number . parseInt ( POINT_LIMITER_IN_MINUTES ) === 1 ? '' : 's'
122+ } .`,
124123 provider : 'spam' ,
125124 title : 'Cooldown alert!' ,
126125 } ) . embed ,
@@ -149,7 +148,7 @@ const handleThanks = async (msg: Message): Promise<void> => {
149148
150149function attachUndoThanksListener ( client : Client ) : void {
151150 client . on ( 'interactionCreate' , async interaction => {
152- if ( ! ( interaction . isButton ( ) || interaction . isSelectMenu ( ) ) ) {
151+ if ( ! ( interaction . isButton ( ) || interaction . isStringSelectMenu ( ) ) ) {
153152 return ;
154153 }
155154 const id = interaction . customId ;
@@ -170,7 +169,7 @@ function attachUndoThanksListener(client: Client): void {
170169
171170 await interaction . deferReply ( { ephemeral : true } ) ;
172171
173- const thanksInteraction : ThanksInteractionType =
172+ const thanksInteraction =
174173 await ThanksInteraction . findOne ( {
175174 responseMsgId : msgId ,
176175 } ) ;
@@ -209,23 +208,32 @@ function attachUndoThanksListener(client: Client): void {
209208 ) ) as TextChannel ;
210209 if ( thanksInteraction . thankees . length === 0 ) {
211210 textChannel . messages . delete ( thanksInteraction . responseMsgId ) ;
212- thanksInteraction . delete ( ) ;
211+ ThanksInteraction . deleteOne ( { _id : thanksInteraction . _id } )
213212 } else {
214213 const oldMsg = await textChannel . messages . fetch ( msgId ) ;
215- oldMsg . embeds [ 0 ] . fields = oldMsg . embeds [ 0 ] . fields
216- . filter ( item => ! removeThankees . includes ( item . value . slice ( 3 , - 1 ) ) )
217- . map ( ( item , x ) => ( { ...item , name : `${ x + 1 } ` } ) ) ;
218-
219- const oldSelect = oldMsg . components [ 0 ] . components [ 0 ] as MessageSelectMenu ;
214+ const updatedEmbeds = [
215+ new EmbedBuilder (
216+ oldMsg . embeds [ 0 ]
217+ ) . setFields (
218+ oldMsg . embeds [ 0 ] . fields
219+ . filter ( item => ! removeThankees . includes ( item . value . slice ( 3 , - 1 ) ) )
220+ . map ( ( item , x ) => ( { ...item , name : `${ x + 1 } ` } ) )
221+ ) ,
222+ ...oldMsg . embeds . slice ( 1 )
223+ ]
224+
225+
226+ const oldSelect = oldMsg . components [ 0 ] . components [ 0 ] ;
227+ if ( oldSelect . type !== ComponentType . StringSelect ) throw new Error ( )
220228 const nuOptions = oldSelect . options
221229 . filter ( item => ! removeThankees . includes ( item . value ) )
222230 . map ( ( { label, value } ) => ( { label, value } ) ) ;
223231
224232 oldMsg . edit ( {
225- embeds : oldMsg . embeds ,
233+ embeds : updatedEmbeds ,
226234 components : [
227- new MessageActionRow ( ) . addComponents (
228- new MessageSelectMenu ( oldSelect )
235+ new ActionRowBuilder < MessageActionRowComponentBuilder > ( ) . addComponents (
236+ new StringSelectMenuBuilder ( oldSelect )
229237 . setOptions ( nuOptions )
230238 . setMaxValues ( nuOptions . length )
231239 ) ,
0 commit comments