Files
bot-discord-coins/commands/gestion/setRolePerm.js
T

78 lines
3.3 KiB
JavaScript

const { EmbedBuilder } = require('discord.js');
const db = require('../../fonctions/database.js');
const embedColor = require('../../fonctions/embedColor.js');
module.exports = {
aliases: ['setperm'],
description: 'Ajoute les permissions d\'un rôle pour utiliser les commandes du bot.',
emote: '⏱️',
utilisation: '<@role|None> <1|2|3|4|5>',
permission: 10,
async execute(message, args, client) {
if (!args[0] || !args[1]) {
const embed = new EmbedBuilder()
.setTitle('⏱️ Ajout de permissions')
.setDescription(`Vous devez spécifier un rôle et un niveau de permission.\n\n**Utilisation:** \`&setRolePerm <@role|None> <1|2|3|4|5>\``)
.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 } });
}
let role;
if (args[0] === 'None') {
role = 'None';
} else {
role = message.mentions.roles.first().id;
}
if (isNaN(parseInt(args[1]))) {
const embed = new EmbedBuilder()
.setTitle('⏱️ Ajout de permissions')
.setDescription('Le deuxième argument doit être un nombre.')
.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 } });
}
if (args[1] < 1 || args[1] > 5) {
const embed = new EmbedBuilder()
.setTitle('⏱️ Ajout de permissions')
.setDescription('Le niveau de permission doit être compris entre 1 et 5.')
.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 } });
}
if (role === 'None') {
db.run(`DELETE FROM rolePermission WHERE guildId = ? AND permission = ?`, [message.guild.id, args[1]]);
const embed = new EmbedBuilder()
.setTitle('⏱️ Ajout de permissions')
.setDescription(`Les permissions de niveau ${args[1]} ont été retirées.`)
.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 } });
}
db.run(`INSERT OR REPLACE INTO rolePermission (guildId, roleId, permission) VALUES (?, ?, ?)`, [message.guild.id, role, args[1]]);
const embed = new EmbedBuilder()
.setTitle('⏱️ Ajout de permissions')
.setDescription(`Le rôle <@&${role}> a maintenant la permission de niveau ${args[1]}.`)
.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 } });
},
};