const { EmbedBuilder } = require("discord.js"); const db = require("../../fonctions/database.js"); const embedColor = require("../../fonctions/embedColor.js"); module.exports = { aliases: ["tedit"], description: "Modifie les informations de votre team.", emote: "🖋️", utilisation: " ", permission: 0, async execute(message, args, client) { if (args.length > 0) { let subCommand = args[0].toLowerCase(); if (!["name", "banner", "icon", "description"].includes(subCommand)) { subCommand = subCommand.replace("nom", "name"); subCommand = subCommand.replace("banniere", "banner"); subCommand = subCommand.replace("bannière", "banner"); subCommand = subCommand.replace("photo", "icon"); subCommand = subCommand.replace("icone", "icon"); if (!["name", "banner", "icon", "description"].includes(subCommand)) { subCommand = subCommand.replace("d", "description"); subCommand = subCommand.replace("n", "name"); subCommand = subCommand.replace("i", "icon"); subCommand = subCommand.replace("p", "icon"); subCommand = subCommand.replace("b", "banner"); } } const newValue = args.slice(1).join(" "); if (["name", "banner", "icon", "description"].includes(subCommand)) { await new Promise((resolve, reject) => { db.run( `UPDATE teams SET ${subCommand} = ? WHERE guildId = ? AND id = (SELECT teamId FROM users WHERE guildId = ? AND userId = ?)`, [newValue, message.guild.id, message.guild.id, message.author.id], (err) => { if (err) reject(err); resolve(); }, ); }); const embed = new EmbedBuilder() .setTitle("🖋️ Modification de team") .setDescription(`La ${subCommand} de votre team a été mise à jour.`) .setColor(await embedColor(message.author.id, message.guild.id)) .setTimestamp() .setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL(), }); return message.reply({ embeds: [embed], allowedMentions: { repliedUser: false }, }); } else { const embed = new EmbedBuilder() .setTitle("🖋️ Modification de team") .setDescription( "❌ Vous devez spécifier ce que vous voulez modifier (nom, banner, icon ou description).", ) .setColor(await embedColor(message.author.id, message.guild.id)) .setTimestamp() .setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL(), }); return message.reply({ embeds: [embed], allowedMentions: { repliedUser: false }, }); } } else { const embed = new EmbedBuilder() .setTitle("🖋️ Modification de team") .setDescription( "Veuillez spécifier ce que vous voulez modifier et la nouvelle valeur.", ) .setColor(await embedColor(message.author.id, message.guild.id)) .setTimestamp() .setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL(), }); return message.reply({ embeds: [embed], allowedMentions: { repliedUser: false }, }); } }, };