Files
gestion/commands/logs/vocallog.js
T
2024-03-01 12:05:29 +01:00

52 lines
1.9 KiB
JavaScript

const { EmbedBuilder, ChannelType } = require('discord.js');
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('myDatabase.db');
module.exports = {
name: 'vocallog',
description: 'Enregistre l\'ID d\'un salon pour les logs vocaux.',
category: 'gestion',
emote: '📝',
utilisation: 'vocallog [#salon/id]',
async execute(message, args) {
let channelId;
const mentionedChannel = message.mentions.channels.first();
if (mentionedChannel) {
channelId = mentionedChannel.id;
} else if (args[0]) {
const channel = message.guild.channels.cache.get(args[0]);
if (channel && channel.type === ChannelType.GuildVoice) {
channelId = args[0];
} else {
return message.reply('Le salon spécifié est invalide ou n\'existe pas dans ce serveur.');
}
} else {
channelId = message.channel.id;
}
let data = await new Promise((resolve, reject) => {
db.get('SELECT value FROM gestion WHERE id = ?', [message.client.user.id], (err, row) => {
if (err) {
console.error(err.message);
reject(err);
}
resolve(row ? JSON.parse(row.value) : {});
});
});
if (!data[message.guild.id]) {
data[message.guild.id] = {};
}
data[message.guild.id].vocallog = channelId;
db.run('INSERT OR REPLACE INTO gestion (id, value) VALUES (?, ?)', [message.client.user.id, JSON.stringify(data)], function(err) {
if (err) {
return console.error(err.message);
}
});
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setDescription(`Le salon de log vocaux a été mis à jour dans le salon <#${channelId}>`);
message.channel.send({ embeds: [embed] });
},
};