-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbillardbot.js
53 lines (43 loc) · 1.72 KB
/
billardbot.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
const fs = require('fs');
const Discord = require('discord.js')
const token = process.env.BOT_SECRET_TOKEN || require('./token').bot_secret_token;
const client = new Discord.Client()
client.commands = new Discord.Collection();
const command_files = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of command_files) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.on('ready', () => {
console.log(`Connected as ${client.user.tag}`);
// List servers the bot is connected to
console.log('Servers:');
for (let [key, value] of client.guilds.cache) {
console.log(`\t[${key}] ${value.name}`);
}
});
client.on('message', message => {
if (message.author.bot) {
console.log(`[${message.guild.name}] [${message.channel.name}] Ignoring message from bot.`);
return;
}
let mentionsBot = message.mentions.users.has(client.user.id);
if(!mentionsBot) {
console.log(`[${message.guild.name}] [${message.channel.name}] Ignoring message not mentioning me.`);
return;
}
console.log(`[${message.guild.name}] [${message.channel.name}] Reacting to message "${message.content}".`)
const args = message.content.split(' ').slice(1);
let command = args.shift().toLowerCase();
if (!client.commands.has(command)) {
message.channel.send('Das Kommando verstehe ich nicht.');
return;
}
try {
client.commands.get(command).execute(message, args);
} catch (error) {
console.error(`[${message.guild.name}] [${message.channel.name}] Error executing command "${command}".`);
message.channel.send('Internal Bot Error');
}
});
client.login(token)