Initial upload of the project in its first usable version
This commit is contained in:
25
src/bot/commands/clearCommand.ts
Normal file
25
src/bot/commands/clearCommand.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import {
|
||||
CommandInteraction, Client, TextChannel, ChannelType, ApplicationCommandType,
|
||||
} from 'discord.js';
|
||||
import { Command } from '@/bot/models/command';
|
||||
|
||||
export const ClearCommand: Command = {
|
||||
name: 'clear',
|
||||
description: 'Delete your interactions with the Chat bot',
|
||||
type: ApplicationCommandType.ChatInput,
|
||||
execute: async (client: Client, interaction: CommandInteraction) => {
|
||||
const channel = client.channels.cache.get(interaction.channelId) as TextChannel;
|
||||
const messages = await channel.messages.fetch({ limit: 100 });
|
||||
const consistentMessages = messages
|
||||
.filter((x) => x.interaction?.user.id === interaction.user.id);
|
||||
|
||||
if (channel.type === ChannelType.GuildText) {
|
||||
await channel.bulkDelete(consistentMessages);
|
||||
} else {
|
||||
await messages.forEach((message) => {
|
||||
if (message.author.id !== client.user?.id) return;
|
||||
message.delete();
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user