Clarify code

This commit is contained in:
Androz2091
2020-04-24 16:45:24 +02:00
parent 21cc63275c
commit 1c1dbcb1e9
10 changed files with 114 additions and 138 deletions

View File

@@ -1,62 +1,59 @@
const Discord = require("discord.js")
const fs = require("fs")
const client = new Discord.Client()
const Discord = require("discord.js");
const fs = require("fs");
const client = new Discord.Client();
const settings = require ("./config/bot.json") //The bot connects using the configuration file
const settings = require ("./config/bot.json") // The bot connects using the configuration file
const emotes = require ("./config/emojis.json") //The bot finds emojis
const { Player } = require("discord-player"); // Create a new Player (Youtube API key is your Youtube Data v3 key)
const { Player } = require("discord-player"); //Create a new Player (Youtube API key is your Youtube Data v3 key)
const player = new Player(client, settings.youtube_api); //To easily access the player
const player = new Player(client, settings.youtube_api); // To easily access the player
client.player = player;
client.on("ready", () => {
console.log("The bot is ready to play music"); //If the bot is ready it sends a message in the console
console.log("The bot is ready to play music"); // If the bot is ready it sends a message in the console
});
client.login(settings.token_bot); //The bot connects thanks to the token
client.on('message', async message => {
client.on('message', async (message) => {
let prefix = settings.prefix
const prefix = settings.prefix;
let messageArray = message.content.split(" ")
let cmd = messageArray[0].toLowerCase();
let args = messageArray.slice(1);
const messageArray = message.content.split(" ");
const cmd = messageArray[0].toLowerCase();
const args = messageArray.slice(1);
if(!message.content.startsWith(prefix)) return;
let commandfile = client.commands.get(cmd.slice(prefix.length)) || client.commands.get(client.aliases.get(cmd.slice(prefix.length)))
const commandfile = client.commands.get(cmd.slice(prefix.length)) || client.commands.get(client.aliases.get(cmd.slice(prefix.length)))
if(commandfile) commandfile.run(client,message,args)
});
})
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
fs.readdir("./commands/", (err, files) => {
let jsfile = files.filter(f => f.split(".").pop() === "js")
fs.readdir("./commands/", (err, files) => {
const jsfiles = files.filter(f => f.split(".").pop() === "js")
if(jsfile.length <= 0) {
return console.log("Couldn't Find Commands !");
if(jsfiles.length <= 0) {
return console.log("Couldn't find any commands!");
}
jsfile.forEach((f, i) => {
jsfiles.forEach((file) => {
console.log(`Run command ${f}`);
console.log(`Loading command ${file}`);
let pull = require(`./commands/${f}`);
const command = require(`./commands/${file}`);
client.commands.set(command.config.name, command);
command.config.aliases.forEach(alias => {
client.aliases.set(alias, command.config.name);
});
client.commands.set(pull.config.name, pull);
pull.config.aliases.forEach(alias => {
client.aliases.set(alias, pull.config.name)
});
})});
});