-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (60 loc) · 2.04 KB
/
index.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
const Discord = require('discord.js');
const helpers = require('./helpers.js');
const client = new Discord.Client();
client.commands = new Discord.Collection(); // makes a discord.collection for all the command objs to be put into
const secret = require('./secret.json');
const prefix = ';';
// get test message with client.channels.cache.get('744430283482333315').messages.fetch('788965435496333342')
const main = () =>
{
checkQuit();
console.log(`Logging in with token ${secret}...\n`);
client.login(secret)
.then(n =>
{
console.log(`Logged in with token ${n}\n`);
return new Promise(resolve =>
// await client readying and log it.
client.once('ready', () =>
{
console.log('Ready to go!');
resolve();
}));
})
.then(() =>
{
client.on('message', (msg) =>
{
if(msg.content.startsWith(prefix) && msg.content !== prefix && !msg.author.bot)
{
const command = msg.content.substring(1).split(' ').shift();
// if we have that command, get it from the collection and run its execute() with args
if(helpers.commands.has(command))
{
console.log(`\nGot a command ${command} from user ${msg.author.username} in guild ${msg.guild} [${getNow()}]`);
helpers.commands.get(command)(msg);
}
}
});
})
.catch(console.log);
};
const getNow = () =>
{
const now = new Date();
return `${now.getDate()}-${now.getMonth()}-${now.getFullYear()} ${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`;
};
// checks to see if the user entered 'q'. if so, end the process.
const checkQuit = () =>
{
process.stdin.once('data', (n) =>
{
if(n.toString().trim() === 'q')
{
console.log("uiting...\n");
helpers.disconnectAll(client).then(() => process.exit(0));
}
else checkQuit();
});
};
main();