main.js
1.37 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
61
//bot basic primer
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = ';';
const fs = require('fs');
const { join } = require('path');
// .ENV
require("dotenv").config();
// chat API
client.brain = require('./util/chatSend');
client.em = require("./util/embed");
client.db = require('quick.db');
// Command Handler
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const commandName = file.split(".")[0];
const command = require(`./commands/${file}`);
console.log(`Attempting to load command ${commandName}`);
client.commands.set(commandName, command);
}
//Ready check
client.once('ready', () => {
console.log([...client.commands])
console.log(`anxietymanager is online.`)
});
//Command Calls
client.on('message', async message => {
if(!message.content.startsWith(prefix)) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command == 'ping'){
message.channel.send('pong!');
}
if(!client.commands.has(command)){
return;
}
try{
client.commands.get(command).run(client, message, args);
} catch(error){
console.error(error);
}
});
client.login(process.env.token);