mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-05 22:01:41 +02:00
54 lines
1.8 KiB
JavaScript
54 lines
1.8 KiB
JavaScript
const sqlite3 = require('sqlite3').verbose();
|
|
|
|
module.exports = {
|
|
name: 'prefix',
|
|
aliases: ['setprefix'],
|
|
description: 'Change le préfixe du bot',
|
|
emote: '🔧',
|
|
utilisation: 'prefix <newprefix/main>',
|
|
category: 'botcontrol',
|
|
|
|
async execute(message, args, client) {
|
|
const db = new sqlite3.Database('myDatabase.db');
|
|
const botId = client.user.id;
|
|
const guildId = message.guild.id;
|
|
|
|
if (args.length < 1) {
|
|
return message.reply('Veuillez spécifier un nouveau préfixe.');
|
|
}
|
|
|
|
let data = await new Promise((resolve, reject) => {
|
|
db.get('SELECT value FROM gestion WHERE id = ?', [botId], (err, row) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
reject(err);
|
|
}
|
|
resolve(row ? JSON.parse(row.value) : {});
|
|
});
|
|
});
|
|
|
|
if (!data.prefixes) {
|
|
data.prefixes = {};
|
|
}
|
|
|
|
if (args[0] === "main") {
|
|
const newPrefix = args[1];
|
|
data.prefixes.main = newPrefix;
|
|
db.run('INSERT OR REPLACE INTO gestion (id, value) VALUES (?, ?)', [botId, JSON.stringify(data)], (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
}
|
|
});
|
|
message.reply(`Le main préfixe a été changé à ${newPrefix}.`);
|
|
} else {
|
|
const newPrefix = args[0];
|
|
data.prefixes[guildId] = newPrefix;
|
|
db.run('INSERT OR REPLACE INTO gestion (id, value) VALUES (?, ?)', [botId, JSON.stringify(data)], (err) => {
|
|
if (err) {
|
|
console.error(err.message);
|
|
}
|
|
});
|
|
message.reply(`Le préfixe a été changé à ${newPrefix}.`);
|
|
}
|
|
},
|
|
}; |