From c9965e913f1694af046cd68ff856167cd36618c0 Mon Sep 17 00:00:00 2001 From: Tutur33 Date: Sat, 2 Mar 2024 21:42:57 +0100 Subject: [PATCH] add base commands --- commands/help.ts | 58 +++++++++++++++++++++++++++++++++++++++++ commands/ping.ts | 7 +++-- events/messageCreate.ts | 4 ++- fonctions/run.ts | 2 +- 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 commands/help.ts diff --git a/commands/help.ts b/commands/help.ts new file mode 100644 index 0000000..68d6f6c --- /dev/null +++ b/commands/help.ts @@ -0,0 +1,58 @@ +import { Message } from "discord.js"; + +interface Command { + name: string; + aliases?: string[]; + description: string; + emote?: string; + utilisation?: string; + category?: string; +} + +module.exports = { + aliases: ['h', 'aide'], + description: 'Affiche la liste des commandes', + emote: '📚', + utilisation: '', + + async execute(message: Message, args: string[], client: any) { + const prefix = '!!' + + if (args[0]) { + const command = client.commands.get(args[0]); + if (!command) { + return message.edit(`Je n'ai pas trouvé de commande nommée "${args[0]}".`); + } + + return message.edit(`# Aide pour la commande ${command.emote ? ` ${command.emote}` : '🔧'} ${command.name}\nUtilisation : \`${prefix}${command.name}${command.utilisation ? ` ${command.utilisation}` : ''}\`\nCatégorie : ${command.category || 'Non spécifiée'}\nAlias : ${command.aliases ? command.aliases.map((alias: string) => `\`${alias}\``).join(', ') : 'Aucun'}`); + + } else { + + let commands: Command[] = []; + for (const command of client.commands?.values() || []) { + const existingCommand = commands.find(cmd => cmd.name === command.name); + if (!existingCommand) { + commands.push(command); + } + } + + let categories: { [key: string]: Command[] } = {}; + commands.forEach((command: any) => { + if (!categories[command.category]) { + categories[command.category] = []; + } + categories[command.category]?.push(command); + }); + + let description = `Pour obtenir de l'aide sur les commandes faite ${prefix}help .\n Il y a ${commands.length} commandes disponibles\n\n`; + + for (const [category, commands] of Object.entries(categories)) { + description += `**Catégorie ${category}**\n`; + description += commands.length > 0 ? '> ' + commands.map(command => `\`${command.name}\``).join(', ') : '> Aucune commande dans cette catégorie'; + description += '\n\n'; + } + + message.edit(`# 📚 Information\n${description}`) + } + }, +}; \ No newline at end of file diff --git a/commands/ping.ts b/commands/ping.ts index 674704a..5128d39 100644 --- a/commands/ping.ts +++ b/commands/ping.ts @@ -1,13 +1,12 @@ -const { ButtonStyle, ButtonBuilder, ActionRowBuilder } = require('discord.js'); +import { Message, Client } from 'discord.js'; module.exports = { aliases: ['latence'], description: 'Avoir la latence du bot.', emote: '⏱️', utilisation: '', - permission: 0, - async execute(message: any, args: string[], client: any) { - message.reply("pong"); + async execute(message: Message, args: string[], client: Client) { + message.edit(`Pong! ${client.ws.ping}ms`); } }; \ No newline at end of file diff --git a/events/messageCreate.ts b/events/messageCreate.ts index 9fb617c..7a4cbc0 100644 --- a/events/messageCreate.ts +++ b/events/messageCreate.ts @@ -14,9 +14,11 @@ module.exports = { try { command.execute(message, args, client); + setTimeout(() => { + if (message.deletable) message.delete(); + }, 300000); } catch (error) { console.error(error); - message.edit("Erreur lors de l'exécution de la commande"); } } } diff --git a/fonctions/run.ts b/fonctions/run.ts index 27d7c8b..88753c2 100644 --- a/fonctions/run.ts +++ b/fonctions/run.ts @@ -1,4 +1,4 @@ -const { Collection } = require('discord.js') +import { Collection } from 'discord.js'; const { Client } = require('discord.js-selfbot-v13'); const loadEvents = require("./loadEvents");