From ab1520b104eaf2bcdb1195ea1f0b8694e91c8b13 Mon Sep 17 00:00:00 2001 From: Tutur33 Date: Tue, 13 Feb 2024 23:28:33 +0100 Subject: [PATCH] init base --- commands/ping.js | 9 +++++ events/client/interactionCreate.js | 19 +++++----- events/client/ready.js | 37 ++++++++++++++------ loaders/loadCommands.js | 56 ++++++++++++++++-------------- loaders/loadEvents.js | 41 +++++++++++----------- main.js | 13 +++---- 6 files changed, 98 insertions(+), 77 deletions(-) create mode 100644 commands/ping.js diff --git a/commands/ping.js b/commands/ping.js new file mode 100644 index 0000000..ae826ed --- /dev/null +++ b/commands/ping.js @@ -0,0 +1,9 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: 'ping', + description: 'Command to check the latency of the bot.', + async execute(message, args, client) { + message.channel.send('test'); + }, +}; \ No newline at end of file diff --git a/events/client/interactionCreate.js b/events/client/interactionCreate.js index b320668..b1e0f4f 100644 --- a/events/client/interactionCreate.js +++ b/events/client/interactionCreate.js @@ -1,14 +1,11 @@ -const { Events, InteractionType } = require("discord.js") +const { Events, InteractionType } = require("discord.js"); module.exports = { - - name :Events.InteractionCreate, - async run(client, interaction) { - - if(interaction.type === InteractionType.ApplicationCommand) { - - const command = client.commands.get(interaction.commandName); - await command.execute(interaction, client); - }; + name: Events.InteractionCreate, + async run(client, interaction) { + if (interaction.type === InteractionType.ApplicationCommand) { + const command = client.commands.get(interaction.commandName); + await command.execute(interaction, client); } -}; \ No newline at end of file + }, +}; diff --git a/events/client/ready.js b/events/client/ready.js index a827bba..64c0a1a 100644 --- a/events/client/ready.js +++ b/events/client/ready.js @@ -1,15 +1,30 @@ -const { Events, ActivityType } = require("discord.js") +const { Events, ActivityType } = require("discord.js"); + module.exports = { + name: Events.ClientReady, + async run(client) { + if (client.commands && Array.isArray(client.commands)) { + client.application.commands.set( + client.commands.map((command) => command.data) + ); + } else { + console.error("Les commandes du client sont manquantes ou mal formatées\n"); + } + console.log(` +[${new Date().toLocaleString()}] Logged in as ${client.user.tag} with: + - ${client.guilds.cache.size} guilds + - ${client.channels.cache.size} channels + - ${client.users.cache.size} users + `); - name : Events.ClientReady, - async run(client) { + client.user.setActivity({ + name: "&help", + type: ActivityType.Streaming, //Playing, Streaming, Listening, Watching, Custom, Competing + url: "https://www.twitch.tv/tuturp33" + }); + const activityTypes = ['Playing', 'Streaming', 'Listening', 'Watching', 'Custom', 'Competing']; + let activityType = activityTypes[client.user.presence.activities[0].type] || 'Unknown'; + console.log(`[${new Date().toLocaleString()}] Bot activity set to ${activityType}: ${client.user.presence.activities[0].name}\n`); - if (client.commands && Array.isArray(client.commands)) { - client.application.commands.set(client.commands.map(command => command.data)); - } else { - console.error('Les commandes du client sont manquantes ou mal formatées'); - } - console.log(`${client.user.username} est en ligne`); - - }, + }, }; \ No newline at end of file diff --git a/loaders/loadCommands.js b/loaders/loadCommands.js index 3e968d4..c1b6ba7 100644 --- a/loaders/loadCommands.js +++ b/loaders/loadCommands.js @@ -1,28 +1,30 @@ -const fs = require('fs'); -const path = require('path'); -module.exports = (client) => { - const loadCommands = (dir) => { - let count = 0; - fs.readdirSync(path.join(__dirname, dir)).forEach(file => { - const filePath = path.join(__dirname, dir, file); - if (fs.statSync(filePath).isDirectory()) { - count += loadCommands(path.join(dir, file)); - } else if (file.endsWith('.js')) { - try { - // Delete the cache for this command file - delete require.cache[require.resolve(filePath)]; - const command = require(filePath); - client.commands.set(command.name, command); - count++; - } catch (error) { - console.error(`Failed to load file: ${filePath}`); // Log any errors - console.error(error); - } - } - }); - return count; - } +const fs = require("fs"); +const path = require("path"); - const totalCommands = loadCommands('../commands'); - console.log(`Commands => ${totalCommands} commandes préfixées chargées sur le bot`); -} \ No newline at end of file +module.exports = (client) => { + let count = 0; + const loadCommands = (dir) => { + fs.readdirSync(path.join(__dirname, dir)).forEach((file) => { + const filePath = path.join(__dirname, dir, file); + if (fs.statSync(filePath).isDirectory()) { + count += loadCommands(path.join(dir, file)); + } else if (file.endsWith(".js")) { + try { + // Delete the cache for this command file + delete require.cache[require.resolve(filePath)]; + const command = require(filePath); + client.commands.set(command.name, command); + count++; + } catch (error) { + console.error(`Failed to load file: ${filePath}\n`, error, '\n'); + //console.error(`Failed to load file: ${filePath}`); // Log any errors + //console.error(error); + } + } + }); + return count; + }; + + const totalCommands = loadCommands("../commands"); + console.log(`Commands => ${totalCommands} commandes préfixées chargées sur le bot\n`); +}; \ No newline at end of file diff --git a/loaders/loadEvents.js b/loaders/loadEvents.js index 54d8ee6..580a177 100644 --- a/loaders/loadEvents.js +++ b/loaders/loadEvents.js @@ -1,23 +1,24 @@ -const fs = require('fs'); -const path = require('path'); +const fs = require("fs"); +const path = require("path"); module.exports = (client) => { + let count = 0; + const loadEvents = (dir) => { + fs.readdirSync(path.join(__dirname, dir)).forEach((file) => { + const filePath = path.join(__dirname, dir, file); + if (fs.statSync(filePath).isDirectory()) { + loadEvents(path.join(dir, file)); + } else if (file.endsWith(".js")) { + // Delete the cache for this command file + delete require.cache[require.resolve(filePath)]; + const event = require(filePath); + client.on(event.name, (...args) => event.run(...args, client)); + console.log(`Event ${event.name} loaded`); + count++; + } + }); + }; - let count = 0; - const loadEvents = (dir) => { - fs.readdirSync(path.join(__dirname, dir)).forEach(file => { - const filePath = path.join(__dirname, dir, file); - if (fs.statSync(filePath).isDirectory()) { - loadEvents(path.join(dir, file)); - } else if (file.endsWith('.js')) { - delete require.cache[require.resolve(filePath)]; - const event = require(filePath); - client.on(event.name, (...args) => event.run(...args, client)); - console.log(`Event ${event.name} loaded`); - count++; - } - }); - } - loadEvents('../events'); - console.log(`Event => ${count} chargé sur le bot`) -} \ No newline at end of file + loadEvents("../events"); + console.log(`Event => ${count} chargé sur le bot\n`); +}; diff --git a/main.js b/main.js index 0e37468..a356bc4 100644 --- a/main.js +++ b/main.js @@ -1,15 +1,12 @@ require('dotenv').config(); const { Client, IntentsBitField, Collection } = require("discord.js"); -const loadCommands = require("./loaders/loadCommands") +const loadCommands = require("./loaders/loadCommands"); const loadEvents = require("./loaders/loadEvents"); + const client = new Client({intents: new IntentsBitField(3276799)}); -client.on('ready', () => { - console.log(`Logged in as ${client.user.tag}!`); -}); (async () => { - await loadCommands(client); - await loadEvents(client); + loadCommands(client); + loadEvents(client); await client.login(process.env.TOKEN); -})(); -client.login(process.env.TOKEN); \ No newline at end of file +})(); \ No newline at end of file