From 407c80aacde8604bd47b2aa56c25136180aac0d9 Mon Sep 17 00:00:00 2001
From: Max LeLoup <52738651+MaxLeLoup@users.noreply.github.com>
Date: Fri, 17 Dec 2021 23:50:05 +0100
Subject: [PATCH] Djs V13 Bot
---
README.md | 47 +++++++++++++++++++++++++++++++
commands/Test/TestCommand.js | 14 ++++++++++
config/config.js | 4 +++
events/logs/ready.js | 3 ++
events/message/messageCreate.js | 49 +++++++++++++++++++++++++++++++++
index.js | 11 ++++++++
package.json | 16 +++++++++++
util/loader.js | 31 +++++++++++++++++++++
8 files changed, 175 insertions(+)
create mode 100644 README.md
create mode 100644 commands/Test/TestCommand.js
create mode 100644 config/config.js
create mode 100644 events/logs/ready.js
create mode 100644 events/message/messageCreate.js
create mode 100644 index.js
create mode 100644 package.json
create mode 100644 util/loader.js
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e074c55
--- /dev/null
+++ b/README.md
@@ -0,0 +1,47 @@
+
Discord Bot Base
+
+
+
+[![Support](https://img.shields.io/static/v1?label=Support&message=Actif&color=vert)](https://discord.gg/95vq89mfvS)
+[![Discord](https://img.shields.io/discord/832296913695932428?label=Discord)](https://discord.gg/95vq89mfvS)
+
+
+
+---
+
+ 🤖 Vous cherchez une base de bot pour faire le vôtre ?
+
+
+
+## 📝 Sommaire
+
+- [Infos](#about)
+- [Comment marche t'il ?](#working)
+- [Usage](#usage)
+- [Auteur](#authors)
+
+## 🧐 Infos
+
+Cette base de bot contient tout ce qu'il faut pour faire un bot parfait !
+
+## 💭 Comment marche t'il ?
+
+Commencer par télécharger le bot.
+
+Une fois que vous l'avez téléchargé et extrais vous n'avez qu'à marquer :
+```
+npm i
+npm run dev/npm start
+```
+
+## 🎈 Usage
+
+Le bot ne contient qu'une commande :
+
+```
+!test
+```
+
+## ✍️ Auteur
+
+- [@OwOMax](https://github.com/OwOMax)
diff --git a/commands/Test/TestCommand.js b/commands/Test/TestCommand.js
new file mode 100644
index 0000000..392e69c
--- /dev/null
+++ b/commands/Test/TestCommand.js
@@ -0,0 +1,14 @@
+const { MessageEmbed } = require("discord.js");
+
+module.exports.run = (bot, message, args) => {
+ message.channel.send('Teste !')
+};
+
+module.exports.help = {
+ name: 'vocal',
+ aliases: ['vc'],
+ category: 'stats',
+ description: 'Renvoie les infos sur les personnes en vocal.',
+ cooldown: 5,
+ usage: '',
+}
\ No newline at end of file
diff --git a/config/config.js b/config/config.js
new file mode 100644
index 0000000..80f78df
--- /dev/null
+++ b/config/config.js
@@ -0,0 +1,4 @@
+module.exports = {
+ TOKEN: "T0K3N",
+ PREFIX: "!"
+}
\ No newline at end of file
diff --git a/events/logs/ready.js b/events/logs/ready.js
new file mode 100644
index 0000000..54b78ba
--- /dev/null
+++ b/events/logs/ready.js
@@ -0,0 +1,3 @@
+module.exports = bot => {
+ console.log(`${bot.user.tag} est en ligne !`)
+};
\ No newline at end of file
diff --git a/events/message/messageCreate.js b/events/message/messageCreate.js
new file mode 100644
index 0000000..cfad16e
--- /dev/null
+++ b/events/message/messageCreate.js
@@ -0,0 +1,49 @@
+const { Collection } = require('discord.js');
+const { PREFIX } = require('../../config/config.js');
+
+module.exports = (bot, message) => {
+ if (message.channel.type === "dm") return;
+ if (!message.content.startsWith(PREFIX) || message.author.bot) return;
+
+ const args = message.content.slice(PREFIX.length).split(/ +/);
+ const commandName = args.shift().toLowerCase();
+ const user = message.mentions.users.first();
+
+ const command = bot.commands.get(commandName) || bot.commands.find(cmd => cmd.help.aliases && cmd.help.aliases.includes(commandName));
+ if (!command) return;
+
+ if (command.help.permissions && !message.member.hasPermission('BAN_MEMBERS')) return message.reply("tu n'as pas les permissions pour taper cette commande !");
+
+ if(command.help.args && !args.length) {
+ let noArgsReply = `Il nous faut des arguments pour cet commande, ${message.author} !`
+
+ if (command.help.usage) noArgsReply += `\nVoici comment utiliser la commande: \`${PREFIX}${command.help.name} ${command.help.usage}.\``
+ return message.channel.send(noArgsReply);
+ }
+
+ if (command.help.isUserAdmin && !user) return message.reply("il faut mentionner un utilisateur !");
+
+ if (command.help.isUserAdmin && message.guild.member(message.mentions.users.first()).hasPermission('BAN_MEMBERS')) return message.reply("tu ne peux pas utiliser cette commande sur cet utilisateur !");
+
+ if (!bot.cooldowns.has(command.help.name)) {
+ bot.cooldowns.set(command.help.name, new Collection());
+ }
+
+ const timeNow = Date.now();
+ const tStamps = bot.cooldowns.get(command.help.name);
+ const cdAmount = (command.help.cooldown || 5) * 1000;
+
+ if (tStamps.has(message.author.id)) {
+ const cdExpirationTime = tStamps.get(message.author.id) + cdAmount;
+
+ if (timeNow < cdExpirationTime) {
+ timeLeft = (cdExpirationTime - timeNow) / 1000;
+ return message.reply(`merci d'attendre ${timeLeft.toFixed(0)} seconde(s) avant de ré-utiliser la commande \`${command.help.name}\``);
+ }
+ }
+
+ tStamps.set(message.author.id, timeNow);
+ setTimeout(() => tStamps.delete(message.author.id), cdAmount);
+
+ command.run(bot, message, args);
+}
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..d679c73
--- /dev/null
+++ b/index.js
@@ -0,0 +1,11 @@
+const { Client, Collection } = require('discord.js');
+const { loadCommands, loadEvents } = require("./util/loader.js")
+const { TOKEN } = require('./config/config.js');
+
+const bot = new Client();
+["commands", "cooldowns"].forEach(x => client[x] = new Collection());
+
+loadCommands(bot);
+loadEvents(bot);
+
+bot.login(TOKEN);
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..be0e672
--- /dev/null
+++ b/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "djs-bot",
+ "version": "1.0.0",
+ "description": "Base de bot fais par ✞ 🅼🅰🆇#0667 ! https://discord.gg/95vq89mfvS :wink:",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "keywords": [],
+ "author": "✞ 🅼🅰🆇#0667",
+ "license": "ISC",
+ "dependencies": {
+ "discord.js": "^13.2.0",
+ "fs": "0.0.1-security"
+ }
+}
diff --git a/util/loader.js b/util/loader.js
new file mode 100644
index 0000000..55d5251
--- /dev/null
+++ b/util/loader.js
@@ -0,0 +1,31 @@
+const { readdirSync } = require("fs");
+
+const loadCommands = (bot, dir = "./commands/") => {
+ readdirSync(dir).forEach(dirs => {
+ const commands = readdirSync(`${dir}/${dirs}/`).filter(files => files.endsWith(".js"));
+
+ for (const file of commands) {
+ const getFileName = require(`../${dir}/${dirs}/${file}`);
+ bot.commands.set(getFileName.help.name, getFileName);
+ console.log(`Commande chargée: ${getFileName.help.name}`);
+ };
+ });
+};
+
+const loadEvents = (bot, dir = "./events/") => {
+ readdirSync(dir).forEach(async dirs => {
+ const events = readdirSync(`${dir}/${dirs}/`).filter(files => files.endsWith(".js"));
+
+ for (const event of events) {
+ const evt = require(`../${dir}/${dirs}/${event}`);
+ const evtName = event.split(".")[0];
+ bot.on(evtName, evt.bind(null, bot));
+ console.log(`Evenement chargé: ${evtName}`);
+ };
+ });
+};
+
+module.exports = {
+ loadCommands,
+ loadEvents,
+};
\ No newline at end of file