-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
71 lines (56 loc) · 2.02 KB
/
main.js
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
62
63
64
65
66
67
68
69
70
71
// Init
const express = require('express');
const app = express();
const port = 3000;
const fs = require('fs');
const faker = require('faker');
app.get('/', (req, res) => res.send('Hello World!'));
app.listen(port, () => console.log(`taotry listening at http://localhost:${port}`));
// Main Code
const {prefix, ping_responses} = require('./config.json');
const Discord = require('discord.js');
const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for(const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity(`taotry`, {type: "LISTENING"})
.then(presence => console.log(`Activity set to ${presence.activities[0].name}`))
.catch(console.error);
});
client.on('message', msg => {
if(msg.content == `<@!${client.user.id}>` || msg.content == `<@${client.user.id}>`) {
msg.reply(ping_responses[Math.floor(Math.random()*ping_responses.length)]);
}
if (!msg.content.toLowerCase().startsWith(prefix) || msg.author.bot) return;
const args = msg.content.slice(prefix.length-1).split(/ +/);
var command_name;
try {
command_name = args.filter((el) => el !== '').shift().toLowerCase();
}
catch {
command_name = null
}
const command = client.commands.get(command_name)
|| client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(command_name));
if(!command) return;
if (command.args && args.length == 2) {
if(command.usage) {
return msg.reply(`${command.argsmessage}\nUsage would be: ${command.usage}`);
}
}
try {
command.execute(msg, args);
} catch (error) {
console.error(error);
msg.reply('there were poblers trying to execute that command!');
}
});
// process.on('unhandledRejection', error => {
// console.error('Unhandled promise rejection:', error);
// });
client.login(process.env.TOKEN);