-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
83 lines (74 loc) · 3.26 KB
/
Copy pathbot.js
File metadata and controls
83 lines (74 loc) · 3.26 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
/*****************************************************************************
* Copyright (C) 2020 Jacob Ashkenas
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const fs = require('fs');
const Discord = require('discord.js');
const client = new Discord.Client();
const config = require('./config.json');
client.on('ready', () => {
console.log(`[Status] Bot logged in as ${client.user.tag}!`)
client.user.setPresence({
activity: {
type: 'WATCHING',
name: `for ${config.prefix}help`
},
status: 'online'
}).catch(console.error);
// Load prompt packs
client.packs = new Discord.Collection();
const packFiles = fs.readdirSync('./prompts').filter((file) => file.endsWith('.json'));
for(const file of packFiles) {
const pack = require(`./prompts/${file}`);
client.packs.set(pack.name.toLowerCase(), pack);
}
// Load commands
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.games = new Discord.Collection();
client.game = 0;
});
client.on('message', (msg) => {
if(!msg.author.bot && msg.content.toLowerCase().startsWith(config.prefix)) {
const args = msg.content.substring(config.prefix.length).split(' ');
const cmdName = args.shift().toLowerCase();
const command = client.commands.get(cmdName) || client.commands.find((cmd) => cmd.aliases && cmd.aliases.includes(cmdName));
if(command) {
if(command.guildOnly && !msg.guild) {
msg.channel.send("That command can only be run in a server!");
return;
} else if(command.guildOnly && command.botPerms && !msg.guild.me.hasPermission(command.botPerms)) {
msg.reply("the bot doesn't have the necessary permissions to do that! Please contact the server owner or admins.");
return;
} else if(command.guildOnly && command.memberPerms && ! msg.member.hasPermission(command.memberPerms)) {
msg.reply("you don't have the necessary permissions to do that!");
return;
}
try {
command.execute(msg, args);
} catch(error) {
console.error(error);
msg.reply("a problem occured while running that command!");
}
if(msg.channel.type !== "dm")
msg.delete({timeout: 1000});
}
}
});
client.login(process.env.TOKEN);