implement fun facts

This commit is contained in:
Lou 2025-11-25 20:56:32 +01:00
parent a8fa55d5d0
commit 2962784d70
6 changed files with 96 additions and 10 deletions

16
utils/commands.js Normal file
View file

@ -0,0 +1,16 @@
import { SlashCommandBuilder } from 'discord.js';
import { getRandomFact } from '../utils/factRandomizer.js';
export default {
// définition de la commande pour Discord
data: new SlashCommandBuilder()
.setName('funfact') // correspondra à /funfact
.setDescription('Donne un fait aléatoire et inutile'),
// action
async execute(interaction) {
const fact = getRandomFact();
// interaction.reply plutôt que message.reply
await interaction.reply(`💡 **Fun fact : **\n${fact}`);
}
};

26
utils/deployCommands.js Normal file
View file

@ -0,0 +1,26 @@
import 'dotenv/config';
import { REST, Routes } from 'discord.js';
import fs from 'fs';
const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = await import(`./commands/${file}`);
commands.push(command.default.data.toJSON());
}
const rest = new REST().setToken(process.env.DISCORD_TOKEN);
(async () => {
try {
console.log('Enregistrement des commandes slash...');
await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands },
);
console.log('Commandes enregistrées ! Tape /funfact sur Discord.');
} catch (error) {
console.error(error);
}
})();