Added complete code documentation

This commit is contained in:
Matias Espinoza
2023-03-20 15:30:26 -03:00
parent 63d2c1ddf1
commit c74ad8d0fc
11 changed files with 159 additions and 25 deletions

View File

@ -8,14 +8,26 @@ export const ClearCommand: Command = {
description: 'Delete your interactions with the Chat bot',
type: ApplicationCommandType.ChatInput,
execute: async (client: Client, interaction: CommandInteraction) => {
/**
* Get the chat history from the channel and filter the messages from the user
*/
const channel = client.channels.cache.get(interaction.channelId) as TextChannel;
const messages = await channel.messages.fetch({ limit: 100 });
const messages = await channel.messages.fetch({ limit: 100 }); // Get the last 100 messages from the channel
const consistentMessages = messages
.filter((x) => x.interaction?.user.id === interaction.user.id);
/**
* Delete the messages from the channel
*/
if (channel.type === ChannelType.GuildText) {
/**
* Bulk delete the messages if the channel is a guild text channel
*/
await channel.bulkDelete(consistentMessages);
} else {
/**
* Delete the messages one by one if the channel is a DM channel
*/
await messages.forEach((message) => {
if (message.author.id !== client.user?.id) return;
message.delete();