1- import type { ClientUser , Message } from "discord.js" ;
1+ import type { Message } from "discord.js" ;
22
33import type { BotContext } from "#context.ts" ;
44
55import * as pollService from "#service/poll.ts" ;
6+ import * as botReplyService from "#service/botReply.ts" ;
67
78import log from "#log" ;
89
9- const deleteInlineRepliesFromBot = ( messageRef : Message < true > , botUser : ClientUser ) =>
10- Promise . allSettled (
11- messageRef . channel . messages . cache
12- . filter ( m => m . author . id === botUser . id && m . reference ?. messageId === messageRef . id )
13- . map ( m => m . delete ( ) ) ,
14- ) ;
10+ async function deleteInlineRepliesFromBot ( message : Message < true > ) {
11+ const botReplies = await botReplyService . getBotRepliesForMessage ( message ) ;
12+ if ( botReplies . length === 0 ) {
13+ return ;
14+ }
15+
16+ const deletePromises = botReplies . map ( async reply => {
17+ try {
18+ const botReplyMessage = await message . channel . messages . fetch ( reply . botReplyMessageId ) ;
19+ await botReplyMessage . delete ( ) ;
20+ } catch ( error ) {
21+ log . warn ( { error, replyId : reply . id } , "Failed to delete bot reply message" ) ;
22+ }
23+ } ) ;
24+
25+ await Promise . allSettled ( deletePromises ) ;
26+
27+ await botReplyService . deleteBotRepliesForMessage ( message ) ;
28+ }
1529
1630export default async function ( message : Message < true > , context : BotContext ) {
1731 if ( message . author . id === context . client . user . id ) {
@@ -23,13 +37,7 @@ export default async function (message: Message<true>, context: BotContext) {
2337
2438 await handlePollDeletion ( message ) ;
2539
26- const isNormalCommand =
27- message . content . startsWith ( context . prefix . command ) ||
28- message . content . startsWith ( context . prefix . modCommand ) ;
29-
30- if ( isNormalCommand ) {
31- await deleteInlineRepliesFromBot ( message , context . client . user ) ;
32- }
40+ await deleteInlineRepliesFromBot ( message ) ;
3341}
3442
3543async function handlePollDeletion ( message : Message < true > ) {
0 commit comments