-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
70 lines (57 loc) · 1.9 KB
/
bot.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
// INITIALISE //
// DISCORD ZONE //
const { Client, Collection, Intents } = require('discord.js');
// intents area
const client = new Client({
intents: [
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILDS,
]
});
client.commands = new Collection();
////////////////////////////////////////
const env = require('dotenv').config();
const path = require('path');
const fs = require('fs');
const helpers = require("./helpers/helpers.js");
////////////////////////////////////////
// FUNCTIONAL ZONE //
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
// fetch commands
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
// get name by removing extension
let commandName = file.split(".")[0];
client.commands.set(commandName, command);
}
// check if message is sent
client.on("messageCreate", (message) => {
if(message.author.bot) return;
if(process.env.MODE == 'local' && message.author.id != '315217872005627914') message.reply('Sorry! Currently under maintenance.');
if(message.content.startsWith(process.env.PREFIX)) {
processCommand(message);
}
});
function processCommand(message) {
let fullCommand = message.content.substr(1);
let splitCommand = fullCommand.split(" ");
let primaryCommand = splitCommand[0];
let args = splitCommand.slice(1);
const command = client.commands.get(primaryCommand);
if (!command) {
message.channel.send(`Sorry, I don't understand that command. Try using \`${process.env.PREFIX}help\` !`);
return;
}
try {
// execute command
command.run(client, message, args);
} catch (error) {
console.error(error);
message.channel.send("Sorry, something went wrong.");
}
}
// CLIENT STARTUP //
client.login(process.env.DISCORD_TOKEN);