bot passer sous TS

This commit is contained in:
Tutur33
2024-02-25 19:15:42 +01:00
parent d85c18f7ed
commit 1f86194f64
16 changed files with 221 additions and 120 deletions
+22 -34
View File
@@ -1,26 +1,13 @@
const { EmbedBuilder, StringSelectMenuBuilder, ActionRowBuilder } = require("discord.js")
/*
module.exports = {
aliases: ['h', 'aide'],
description: 'Affiche la liste des commandes',
emote: '📚',
utilisation: '[commande]',
async execute(message, args, client) {
console.log("Liste des commandes :");
let commands = [];
for (const command of client.commands.values()) {
const existingCommand = commands.find(cmd => cmd.name === command.name);
if (!existingCommand) {
commands.push(command);
}
}
console.log(commands);
},
};
*/
import { Message, EmbedBuilder } from "discord.js";
interface Command {
name: string;
aliases?: string[];
description: string;
emote?: string;
utilisation?: string;
category?: string;
}
module.exports = {
aliases: ['h', 'aide'],
@@ -28,15 +15,16 @@ module.exports = {
emote: '📚',
utilisation: '[commande]',
async execute(message, args, client) {
const prefix = '+'
async execute(message: Message, args: string[], client: any) {
const prefix = '+';
if (args[0]) {
const command = client.commands.get(args[0]);
if (!command) {
return message.reply(`Je n'ai pas trouvé de commande nommée "${args[0]}".`);
}
const commandPerm = 'None'
const commandPerm = 'None';
const embed_command = new EmbedBuilder()
.setColor('#0099ff')
@@ -45,30 +33,30 @@ module.exports = {
.addFields(
{ name: 'Utilisation', value: `\`${prefix}${command.utilisation ? `${command.utilisation}` : ''}\``, inline: true },
{ name: 'Catégorie', value: command.category || 'Non spécifiée', inline: true },
{ name: 'Alias', value: command.aliases ? command.aliases.map(alias => `\`${alias}\``).join(', ') : 'Aucun', inline: true },
{ name: 'Alias', value: command.aliases ? command.aliases.map((alias: string) => `\`${alias}\``).join(', ') : 'Aucun', inline: true },
{ name: 'Permissions', value: `Perm level: ${commandPerm}` || 'Indéfini', inline: true },
)
.setTimestamp()
.setFooter({text: `${client.user.tag} © 2024`, iconURL: client.user.displayAvatarURL({dynamic: true})})
.setFooter({ text: `${client.user?.tag} © 2024`, iconURL: client.user?.displayAvatarURL({ dynamic: true })});
return message.reply({ embeds: [embed_command] });
return message.reply({ embeds: [embed_command] });
} else {
let commands = [];
for (const command of client.commands.values()) {
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 = {};
commands.forEach((command) => {
let categories: { [key: string]: Command[] } = {};
commands.forEach((command: any) => {
if (!categories[command.category]) {
categories[command.category] = [];
}
categories[command.category].push(command);
categories[command.category]?.push(command);
});
const embed = new EmbedBuilder()
@@ -79,7 +67,7 @@ module.exports = {
for (const [category, commands] of Object.entries(categories)) {
embed.addFields({
name: `Catégorie ${category}`,
value: commands.map(command => `\`${command.name}\` - ${command.description}`).join('\n')
value: commands.map((command: Command) => `\`${command.name}\` - ${command.description}`).join('\n')
});
}
+1 -3
View File
@@ -1,5 +1,3 @@
const { ButtonStyle, ButtonBuilder, ActionRowBuilder } = require('discord.js');
module.exports = {
aliases: ['latence'],
description: 'Avoir la latence du bot.',
@@ -7,7 +5,7 @@ module.exports = {
utilisation: '',
permission: 0,
async execute(message, args, client) {
async execute(message: any, args: any, client: any) {
message.reply('Pong !');
},
};
@@ -1,6 +1,5 @@
const { ButtonStyle, ButtonBuilder, ActionRowBuilder } = require('discord.js');
const sqlite3 = require('sqlite3').verbose();
require('dotenv').config();
import sqlite3 from 'sqlite3';
import { Message } from 'discord.js';
module.exports = {
aliases: ['prefixset'],
@@ -9,16 +8,16 @@ module.exports = {
utilisation: '',
permission: 10,
async execute(message, args, client) {
async execute(message: Message, args: string[]) {
if (args.length < 1) return message.reply('Veuillez entrer un préfixe.');
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE, (err) => {
let db = new sqlite3.Database('db.db', sqlite3.OPEN_READWRITE, (err: Error | null) => {
if (err) {
console.error(err.message);
}
});
db.run('INSERT OR REPLACE INTO prefix (serverID, prefix) VALUES (?, ?)', [message.guild.id, args[0]], (err) => {
db.run('INSERT OR REPLACE INTO prefix (serverID, prefix) VALUES (?, ?)', [message.guild?.id, args[0]], (err: Error | null) => {
if (err) {
console.error(err.message);
message.reply('Erreur lors de la modification du préfixe.');
@@ -27,7 +26,7 @@ module.exports = {
}
});
db.close((err) => {
db.close((err: Error | null) => {
if (err) {
console.error(err.message);
}