Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·60 lines (50 loc) · 1.51 KB
/
Copy pathindex.js
File metadata and controls
executable file
·60 lines (50 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//Bring in packages for node to use
const Discord = require("discord.js");
const fs = require("fs");
//Import settings
const botsettings = require("./botsettings.json");
//Initialize Bot Object
const bot = new Discord.Client({disableEveryone: true});
bot.commands = new Discord.Collection();
fs.readdir("./commands/", (err,files) => {
if(err) console.error(err);
let jsfiles = files.filter(f => f.split(".").pop() === "js");
if(jsfiles.length <= 0){
console.log("No commands to load!");
return;
}
console.log(`Loading ${jsfiles.length} commands!`);
jsfiles.forEach((f,i) => {
let props = require(`./commands/${f}`);
console.log(`${i+1}: ${f} loaded.`);
bot.commands.set(props.help.name,props);
});
});
bot.on("ready",() => {
console.log("I'm online")
})
bot.on("message",message => {
if(message.author.bot) return;
if(message.content == "ayy lmao")
{
message.channel.send("ayy lmao")
}
if(!message.content.startsWith(botsettings.prefix)) return;
let args = message.content.split(/\s+/g);
let command = args[0].toLowerCase().slice(1);
args = args.slice(1);
if(command == "help")
{
message.channel.send("I don't have any commands")
}
cmd = bot.commands.get(command);
if(cmd)
{
cmd.run(bot,message,args)
.catch(error =>{
console.error("This command failed: "+command+"\n"+error);
})
}
})
//Login to discord
bot.login(botsettings.token);