add anti crash + command

This commit is contained in:
Tutur33
2024-03-15 20:35:35 +01:00
parent deac21bd8e
commit 51e2d61358
14 changed files with 208 additions and 46 deletions
+35
View File
@@ -0,0 +1,35 @@
import { Message, Client, ButtonStyle, ButtonBuilder, ActionRowBuilder } from "discord.js";
module.exports = {
aliases: ['addbuttonurl', 'addurlbtn', 'addurlbutton'],
description: 'Ajoute un bouton url',
emote: '🔗',
utilisation: '[url] [message ID] [label]',
permission: 10,
async execute(message: Message, args: string[], client: Client) {
if (!args[0]) return message.reply('Veuillez fournir une url');
if (!args[1]) return message.reply('Veuillez fournir un ID de message');
if (!args[2]) return message.reply('Veuillez fournir un label');
const url = args[0];
const messageId = args[1];
const label = args.slice(2).join(' ');
if (url && !/^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/.test(url)) {
return message.reply('Veuillez fournir une URL valide');
}
const button = new ButtonBuilder()
.setLabel(label)
.setURL(url)
.setStyle(ButtonStyle.Link);
const row: any = new ActionRowBuilder()
.addComponents(button);
const msg = await message.channel.messages.fetch(messageId);
if (!msg) return message.reply('Message introuvable');
if (msg.author.id !== client.user?.id) return message.reply('Ce message n\'a pas été envoyé par moi');
msg.edit({ components: [row] });
},
};
+28
View File
@@ -0,0 +1,28 @@
import { Message, EmbedBuilder } from "discord.js";
module.exports = {
aliases: ['allbots'],
description: 'Affiche tous les bots sur le serveur',
emote: '🤖',
utilisation: '',
permission: 0,
async execute(message: Message) {
if (!message.guild) return message.reply('Cette commande ne peut être utilisée que dans un serveur');
const bots = message.guild.members.cache.filter(member => member.user.bot);
const embed = new EmbedBuilder()
.setTitle('Liste des bots présents')
.setColor('#0099ff');
if (bots.size > 0) {
const botList = Array.from(bots.values()).map((bot, index) => `${index + 1} - <@${bot.id}>`).join('\n');
embed.setDescription(botList);
embed.setFooter({ text: `Total : ${bots.size}`});
} else {
embed.setDescription('Il n\'y a pas de bot sur le serveur');
}
message.channel.send({ embeds: [embed] });
},
};
+28
View File
@@ -0,0 +1,28 @@
import { Message, EmbedBuilder, PermissionsBitField } from "discord.js";
module.exports = {
aliases: ['alladmins'],
description: 'Affiche tous les membres avec la permission d\'administrateur sur le serveur',
emote: '🔧',
utilisation: '',
permission: 0,
async execute(message: Message) {
if (!message.guild) return message.reply('Cette commande ne peut être utilisée que dans un serveur');
const admins = message.guild.members.cache.filter(member => member.permissions.has(PermissionsBitField.Flags.Administrator));
const embed = new EmbedBuilder()
.setTitle('Administrateurs sur le serveur')
.setColor('#0099ff');
if (admins.size > 0) {
const adminList = Array.from(admins.values()).map((admin, index) => `${index + 1} - <@${admin.id}>`).join('\n');
embed.setDescription(adminList);
embed.setFooter({ text :`Total : ${admins.size}`});
} else {
embed.setDescription('Il n\'y a pas d\'administrateur sur le serveur');
}
message.channel.send({ embeds: [embed] });
},
};
+38
View File
@@ -0,0 +1,38 @@
const fetch = require('node-fetch');
import { Message, Client, EmbedBuilder } from "discord.js";
module.exports = {
aliases: ['bannière', 'banniere'],
description: 'Affiche la bannière d\'un utilisateur',
emote: '🔍',
utilisation: '<@user>',
permission: 0,
async execute(message: Message, args: string[], client: Client) {
const user = message.mentions.users.first() || message.author;
const response = await fetch(`https://discord.com/api/users/${user.id}`, {
method: 'GET',
headers: {
Authorization: `Bot ${message.client.token}`
}
});
const data = await response.json();
if (!data.banner) {
return message.reply('Cet utilisateur n\'a pas de bannière.');
}
const format = data.banner.startsWith('a_') ? 'gif' : 'png';
const bannerURL = `https://cdn.discordapp.com/banners/${user.id}/${data.banner}.${format}?size=2048`;
const embed = new EmbedBuilder()
.setTitle(`Bannière de ${user.tag}`)
.setImage(bannerURL)
.setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() })
.setTimestamp();
message.reply({ embeds: [embed] });
},
};
+118
View File
@@ -0,0 +1,118 @@
import { Message, EmbedBuilder, StringSelectMenuBuilder, ActionRowBuilder } from "discord.js";
const getServerPrefix = require("../../fonctions/getServerPrefix");
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: '[commande]',
async execute(message: Message, args: string[], client: any) {
const prefix = await getServerPrefix(message.guild?.id);
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 embed_command = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(`Aide pour la commande ${command.emote ? ` ${command.emote}` : '🔧'} ${command.name}`)
.setDescription(command.description)
.addFields(
{ name: 'Utilisation', value: `\`${prefix}${command.name}${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: string) => `\`${alias}\``).join(', ') : 'Aucun', inline: true },
{ name: 'Permissions', value: `Perm level: ${command.permission}` || 'Indéfini', inline: true },
)
.setTimestamp()
.setFooter({ text: `${client.user?.tag} © 2024`, iconURL: client.user?.displayAvatarURL({ dynamic: true })});
return message.reply({ embeds: [embed_command] });
} 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 = `Sélectionnez une catégorie parmi les options ci-dessous pour obtenir de l'aide sur les commandes correspondantes.\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';
}
const embeds: any = {home: new EmbedBuilder()
.setTitle('📚 Information')
.setDescription(description)
.setColor('#0099ff')
.setThumbnail(message.guild?.iconURL() ?? null)
.setFooter({text: `${client.user.tag} © 2024`, iconURL: client.user.displayAvatarURL({dynamic: true})})
.setTimestamp()
};
for (const [category, commands] of Object.entries(categories)) {
let description;
if (commands.length > 0) {
description = commands.map(command => `${command.emote ? ` ${command.emote}` : '🔧'} **${prefix}${command.name ? ` ${command.name} ${command.utilisation}` : ''}**\n \`${command.description}\``).join('\n');
} else {
description = 'Aucune commande dans cette catégorie.';
}
embeds[category] = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(`Catégorie ${category}`)
.setDescription(description)
.setTimestamp()
.setFooter({text: `${client.user.tag} © 2024`, iconURL: client.user.displayAvatarURL({dynamic: true})})
}
const menu = new StringSelectMenuBuilder()
.setCustomId('help_menu')
.setPlaceholder('Sélectionnez une catégorie')
.addOptions([
{ label: 'Accueil', value: 'home' },
...Object.keys(categories).map(category => ({ label: `Catégorie ${category}`, value: category })),
]);
const row: any = new ActionRowBuilder()
.addComponents(menu);
const sentMessage = await message.reply({ embeds: [embeds.home], components: [row] });
const filter = (i: any) => i.customId === 'help_menu' && i.user.id === message.author.id;
const collector = sentMessage.createMessageComponentCollector({ filter, time: 60000 });
collector.on('collect', async (interaction: any) => {
await interaction.update({ embeds: [embeds[interaction.values[0]]] });
});
collector.on('end', () => {
sentMessage.edit({ components: [] });
});
}
},
};
+38
View File
@@ -0,0 +1,38 @@
const { ButtonStyle, ButtonBuilder, ActionRowBuilder } = require('discord.js');
module.exports = {
aliases: ['latence'],
description: 'Avoir la latence du bot.',
emote: '⏱️',
utilisation: '',
permission: 0,
async execute(message: any, args: string[], client: any) {
const ping = new ButtonBuilder()
.setCustomId('confirm')
.setLabel('🔄')
.setStyle(ButtonStyle.Primary);
const row = new ActionRowBuilder()
.addComponents(ping);
const sentMessage = await message.reply({
content: `La latence est de : ${client.ws.ping}`,
components: [row],
});
const filter = (i: any) => i.customId === 'confirm' && i.user.id === message.author.id;
const collector = sentMessage.createMessageComponentCollector({ filter, time: 15000 })
collector.on('collect', async (interaction: any) => {
sentMessage.edit({
content: `La latence est de : ${client.ws.ping}`,
components: [row],
});
interaction.reply({ content: 'La latence a été rafraichie', ephemeral: true });
});
collector.on('end', () => {
sentMessage.edit({ components: [] });
});
}
};