22 ApplicationCommandOptionType ,
33 ChannelType ,
44 EmbedBuilder ,
5+ GuildChannel ,
56 PermissionFlagsBits ,
7+ TextBasedChannel ,
68 User ,
79 type Client ,
810 type CommandInteraction ,
@@ -17,7 +19,7 @@ import {
1719 REPEL_DEFAULT_TIMEOUT ,
1820} from '../../env' ;
1921import { DiscordAPIErrorCode } from '../../../enums' ;
20- import { logEmbed } from '../../utils/channel-logger' ;
22+ import { logEmbed , logSimple } from '../../utils/channel-logger' ;
2123
2224enum RepelCommandOptions {
2325 TARGET = 'target' ,
@@ -236,11 +238,22 @@ export const repelInteraction: CommandDataWithHandler = {
236238 false ,
237239 ) ?? REPEL_DEFAULT_DELETE_COUNT ;
238240 let deletedCount = 0 ;
239- const textChannels = interaction . guild . channels . cache . filter (
240- ch => ch . type === ChannelType . GuildText ,
241- ) ;
241+ const textChannels = interaction . guild . channels . cache
242+ . filter (
243+ ( ch ) : ch is TextChannel =>
244+ ( ch . type === ChannelType . GuildText ||
245+ ch . type === ChannelType . GuildVoice ) &&
246+ ch . id !== interaction . channelId &&
247+ Boolean ( ch . lastMessageId ) ,
248+ )
249+ . sort ( ( a , b ) => {
250+ const aLastMessage = a . lastMessageId ? BigInt ( a . lastMessageId ) : 0n ;
251+ const bLastMessage = b . lastMessageId ? BigInt ( b . lastMessageId ) : 0n ;
252+ return Number ( bLastMessage - aLastMessage ) ;
253+ } )
254+ . first ( 50 ) ;
242255
243- for ( const [ , channel ] of textChannels ) {
256+ for ( const channel of [ interaction . channel , ... textChannels ] ) {
244257 if ( deletedCount >= messagesToDelete ) break ;
245258
246259 try {
@@ -289,10 +302,15 @@ export const repelInteraction: CommandDataWithHandler = {
289302 } ) ;
290303 }
291304
305+ const channelInfo =
306+ interaction . channel ?. type === ChannelType . GuildVoice
307+ ? `**${ interaction . channel . name } ** voice chat`
308+ : `<#${ interaction . channelId } >` ;
309+
292310 const embed = new EmbedBuilder ( )
293311 . setTitle ( 'Repel Action' )
294312 . setDescription (
295- `<@${ targetId } > has been repelled by <@${ member . id } > in <# ${ interaction . channelId } > .` ,
313+ `<@${ targetId } > has been repelled by <@${ member . id } > in ${ channelInfo } .` ,
296314 )
297315 . addFields (
298316 {
0 commit comments