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' ;
3
3
import type { Client } from 'discord.js' ;
4
4
5
5
import { POINT_LIMITER_IN_MINUTES } from '../../env.js' ;
@@ -41,7 +41,7 @@ const handleThanks = async (msg: Message): Promise<void> => {
41
41
const reply = await getReply ( msg ) ;
42
42
if ( botId || ( msg . mentions . users . size === 0 && ! reply ) ) {
43
43
if (
44
- [ 'GUILD_PRIVATE_THREAD' , 'GUILD_PUBLIC_THREAD' ] . includes ( msg . channel . type )
44
+ [ ChannelType . PrivateThread , ChannelType . PublicThread ] . includes ( msg . channel . type )
45
45
) {
46
46
await handleThreadThanks ( msg ) ;
47
47
}
@@ -118,9 +118,8 @@ const handleThanks = async (msg: Message): Promise<void> => {
118
118
value : `<@!${ u . id } >\n${ diff } minute${ diff === 1 ? '' : 's' } .` ,
119
119
} ;
120
120
} ) ,
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
+ } .`,
124
123
provider : 'spam' ,
125
124
title : 'Cooldown alert!' ,
126
125
} ) . embed ,
@@ -149,7 +148,7 @@ const handleThanks = async (msg: Message): Promise<void> => {
149
148
150
149
function attachUndoThanksListener ( client : Client ) : void {
151
150
client . on ( 'interactionCreate' , async interaction => {
152
- if ( ! ( interaction . isButton ( ) || interaction . isSelectMenu ( ) ) ) {
151
+ if ( ! ( interaction . isButton ( ) || interaction . isStringSelectMenu ( ) ) ) {
153
152
return ;
154
153
}
155
154
const id = interaction . customId ;
@@ -170,7 +169,7 @@ function attachUndoThanksListener(client: Client): void {
170
169
171
170
await interaction . deferReply ( { ephemeral : true } ) ;
172
171
173
- const thanksInteraction : ThanksInteractionType =
172
+ const thanksInteraction =
174
173
await ThanksInteraction . findOne ( {
175
174
responseMsgId : msgId ,
176
175
} ) ;
@@ -209,23 +208,32 @@ function attachUndoThanksListener(client: Client): void {
209
208
) ) as TextChannel ;
210
209
if ( thanksInteraction . thankees . length === 0 ) {
211
210
textChannel . messages . delete ( thanksInteraction . responseMsgId ) ;
212
- thanksInteraction . delete ( ) ;
211
+ ThanksInteraction . deleteOne ( { _id : thanksInteraction . _id } )
213
212
} else {
214
213
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 ( )
220
228
const nuOptions = oldSelect . options
221
229
. filter ( item => ! removeThankees . includes ( item . value ) )
222
230
. map ( ( { label, value } ) => ( { label, value } ) ) ;
223
231
224
232
oldMsg . edit ( {
225
- embeds : oldMsg . embeds ,
233
+ embeds : updatedEmbeds ,
226
234
components : [
227
- new MessageActionRow ( ) . addComponents (
228
- new MessageSelectMenu ( oldSelect )
235
+ new ActionRowBuilder < MessageActionRowComponentBuilder > ( ) . addComponents (
236
+ new StringSelectMenuBuilder ( oldSelect )
229
237
. setOptions ( nuOptions )
230
238
. setMaxValues ( nuOptions . length )
231
239
) ,
0 commit comments