commit 929d8abc8713157d7ed01829504093d4740bdec1 Author: Fabienmcl Date: Fri Apr 26 16:33:00 2024 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3dde887 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +node_modules/ + +package-lock.json + +package.json + +.env \ No newline at end of file diff --git a/commands/utils/ping.js b/commands/utils/ping.js new file mode 100644 index 0000000..05c8bc4 --- /dev/null +++ b/commands/utils/ping.js @@ -0,0 +1,10 @@ +module.exports = { + + name: "ping", + description: "Get the bot latency ", + + async run(client, message) { + + message.reply(`Ping : \`${client.ws.ping}ms\`.`); + } +}; \ No newline at end of file diff --git a/events/bot/ready.js b/events/bot/ready.js new file mode 100644 index 0000000..c253677 --- /dev/null +++ b/events/bot/ready.js @@ -0,0 +1,12 @@ +const { Events, ActivityType } = require("discord.js"); + +module.exports = { + + name: Events.ClientReady, + run(client) { + + client.user.setActivity("Fortnite", {type: ActivityType.Playing}) + + console.log(`${client.user.username} is online`); + } +}; \ No newline at end of file diff --git a/events/message/messageCreate.js b/events/message/messageCreate.js new file mode 100644 index 0000000..b19e2c9 --- /dev/null +++ b/events/message/messageCreate.js @@ -0,0 +1,15 @@ +const { Events } = require ("discord.js"); + +module.exports = { + name: Events.MessageCreate, + run(client, message) { + const prefix = "!"; + if(!message.content.startsWith(prefix)) return; + + const arrayMessage = message.content.split(" "); + const name = arrayMessage[0].slice(prefix.length, arrayMessage[0].length); + const command = client.commands.get(name); + + command.run(client, message); + } +}; \ No newline at end of file diff --git a/loaders/loadCommands.js b/loaders/loadCommands.js new file mode 100644 index 0000000..ff64a9d --- /dev/null +++ b/loaders/loadCommands.js @@ -0,0 +1,18 @@ +const { readdirSync } = require("fs"); + +module.exports = client => { + + let count = 0; + const dirsCommands = readdirSync("./commands/"); + + for(const dirs of dirsCommands) { + const filesDirs = readdirSync(`./commands/${dirs}/`).filter(f => f.endsWith(".js")); + for(const files of filesDirs) { + const command = require(`../commands/${dirs}/${files}`); + client.commands.set(command.name, command); + count ++; + }; + }; + + console.log(`[Commands] => ${count} logged commands`); +} \ No newline at end of file diff --git a/loaders/loadEvents.js b/loaders/loadEvents.js new file mode 100644 index 0000000..d7f9dc7 --- /dev/null +++ b/loaders/loadEvents.js @@ -0,0 +1,18 @@ +const { readdirSync} = require("fs"); + +module.exports = client => { + + let count = 0; + const dirsEvents = readdirSync("./events/"); + + for(const dirs of dirsEvents) { + const filesDirs = readdirSync(`./events/${dirs}/`).filter(f => f.endsWith(".js")); + for(const files of filesDirs) { + const event = require(`../events/${dirs}/${files}`); + client.on(event.name, (...args) => event.run(client, ...args)); + count++; + }; + }; + + console.log(`[Events] => ${count} logged events`) +} \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..e55d8c5 --- /dev/null +++ b/main.js @@ -0,0 +1,14 @@ +const { Client, IntentsBitField, Collection } = require("discord.js"); +const client = new Client({intents: new IntentsBitField(3276799)}); +const loadCommands = require("./loaders/loadCommands"); +const loadEvents = require("./loaders/loadEvents"); +const dotenv = require("dotenv"); +dotenv.config(); + +client.commands = new Collection(); + +loadCommands(client); +loadEvents(client); + +client.login(process.env.TOKEN); +