diff --git a/src/v2/commands/repel/index.ts b/src/v2/commands/repel/index.ts index e017d810..b4f68a11 100644 --- a/src/v2/commands/repel/index.ts +++ b/src/v2/commands/repel/index.ts @@ -162,7 +162,6 @@ export const repelInteraction: CommandDataWithHandler = { RepelCommandOptions.TARGET, false, )?.user as User; - console.log('Target User:', targetUser); let targetGuildMember: GuildMember | null = null; let userNotInServer = false; @@ -236,11 +235,22 @@ export const repelInteraction: CommandDataWithHandler = { false, ) ?? REPEL_DEFAULT_DELETE_COUNT; let deletedCount = 0; - const textChannels = interaction.guild.channels.cache.filter( - ch => ch.type === ChannelType.GuildText, - ); + const textChannels = interaction.guild.channels.cache + .filter( + (ch): ch is TextChannel => + (ch.type === ChannelType.GuildText || + ch.type === ChannelType.GuildVoice) && + ch.id !== interaction.channelId && + Boolean(ch.lastMessageId), + ) + .sort((a, b) => { + const aLastMessage = a.lastMessageId ? BigInt(a.lastMessageId) : 0n; + const bLastMessage = b.lastMessageId ? BigInt(b.lastMessageId) : 0n; + return Number(bLastMessage - aLastMessage); + }) + .first(50); - for (const [, channel] of textChannels) { + for (const channel of [interaction.channel, ...textChannels]) { if (deletedCount >= messagesToDelete) break; try { @@ -289,10 +299,15 @@ export const repelInteraction: CommandDataWithHandler = { }); } + const channelInfo = + interaction.channel?.type === ChannelType.GuildVoice + ? `**${interaction.channel.name}** voice chat` + : `<#${interaction.channelId}>`; + const embed = new EmbedBuilder() .setTitle('Repel Action') .setDescription( - `<@${targetId}> has been repelled by <@${member.id}> in <#${interaction.channelId}>.`, + `<@${targetId}> has been repelled by <@${member.id}> in ${channelInfo}.`, ) .addFields( {