forked from GeorgeCiesinski/poke-guesser-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupCommands.js
48 lines (39 loc) · 1.93 KB
/
setupCommands.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
/*
LIBRARIES
*/
require('dotenv').config();
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const Commands = require('./commands.js');
/*
OBJECTS, TOKENS, GLOBAL VARIABLES
*/
const client = new Client({intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.DirectMessages, GatewayIntentBits.MessageContent], partials: [Partials.User, Partials.Channel, Partials.GuildMember, Partials.Message, Partials.Reaction]}); // Discord Object
const mySecret = process.env['TOKEN']; // Discord Token
// Outputs console log when bot is logged in and registers all commands
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`); // Logging
const registerObject = Commands.getRegisterObject();
let promises = [];
promises.push(client.application?.commands?.create(registerObject['help']));
promises.push(client.application?.commands?.create(registerObject['settings']));
promises.push(client.application?.commands?.create(registerObject['catch']));
promises.push(client.application?.commands?.create(registerObject['leaderboard']));
promises.push(client.application?.commands?.create(registerObject['score']));
promises.push(client.application?.commands?.create(registerObject['explore']));
promises.push(client.application?.commands?.create(registerObject['reveal']));
promises.push(client.application?.commands?.create(registerObject['mod']));
Promise.all(promises).then(reolvedPromises => {
process.kill(process.pid, 'SIGTERM');
});
});
/*
BOT START CODE (login, start server, etc)
This section checks if there is a TOKEN secret and uses it to login if it is found. If not, the bot outputs a log to the console and terminates.
*/
if (!mySecret) {
console.log("TOKEN not found! You must setup the Discord TOKEN as per the README file before running this bot.");
process.kill(process.pid, 'SIGTERM'); // Kill Bot
} else {
// Logs in with secret TOKEN
client.login(mySecret);
}