-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbot.js
More file actions
87 lines (78 loc) · 2.36 KB
/
bot.js
File metadata and controls
87 lines (78 loc) · 2.36 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const config = require('./config.json');
const Files = require('fs');
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.commands = [];
Files.readdir('./commands/', (err, files) => {
if (err) {
console.error(err);
process.exit(1);
}
files.forEach((file, index) => {
console.log(file);
if (file.endsWith('.command.js'))
bot.commands.push(require('./commands/' + file)(bot, config));
});
});
function updatePresence() {
let guilds = bot.guilds ? bot.guilds.array().length : 0;
bot.user.setPresence({
status: 'online',
game: {
name: `in ${guilds} guild${guilds === 1 ? '' : 's'} | ${
config.prefix
}help`
}
});
}
bot.on('ready', () => {
updatePresence();
console.log('Connected to discord.');
});
bot.on('guildCreate', guild => updatePresence());
bot.on('guildDelete', guild => updatePresence());
bot.on('message', event => {
let message = event.content.toLowerCase();
if (message.startsWith(config.prefix)) {
message = message.replace(config.prefix, '');
let args = message.split(' ');
let cmd = args[0];
args.splice(0, 1);
if (event) {
if (event.guild) {
event.guild
.fetchMember(event.author)
.then(member =>
bot.commands.forEach(command => {
if (command.aliases.indexOf(cmd.toLowerCase()) !== -1) {
console.log(
`[${event.guild.name} (${event.guild.id})] ${
event.author.username
}#${event.author.discriminator}: ${
config.prefix
}${cmd} ${args.join(' ')}`
);
command.onCommand(event, member, event.channel, args);
}
})
)
.catch(console.error);
} else {
bot.commands.forEach(command => {
if (command.aliases.indexOf(cmd.toLowerCase()) !== -1) {
console.log(
`[${event.guild.name} (${event.guild.id})] ${
event.author.username
}#${event.author.discriminator}: ${
config.prefix
}${cmd} ${args.join(' ')}`
);
if (command.allowDM) command.onCommand(event, null, event.channel, args);
}
})
.catch(console.error);
}
}
}
});
bot.login(config.token);