-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
97 lines (67 loc) · 2.93 KB
/
index.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require("dotenv").config();
const mongoose = require('C:/Users/R_a_g/OneDrive/Documents/code/js/discordjs/elitex-support/mongodb/mongoose.js')
;const { Intents,Client,Collection} = require('discord.js');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
const slash_command_files = fs.readdirSync("./slashcommands").filter((filter) => filter.endsWith('.js') );
const event_files = fs.readdirSync('./events').filter((filter) => filter.endsWith('.js'));
const slash_commands_arr=[];
const intents = new Intents(32767);
const client = new Client({
intents: intents
});
client.slash_commands = new Collection();
/////////////////////////////////////////////// Slash Command handler /////////////////////////////////////
for (let f of slash_command_files)
{
const file = require(`C:/Users/R_a_g/OneDrive/Documents/code/js/discordjs/elitex-support/slashcommands/${f}`)
slash_commands_arr.push(file.data.toJSON());
console.log(`Loaded Slash Command ${file.data.name}`);
client.slash_commands.set(file.data.name, file)
}
////////////////////////////////////////////// Event Handler ///////////////////////////////////////////
for (let e of event_files)
{
const event = require(`C:/Users/R_a_g/OneDrive/Documents/code/js/discordjs/elitex-support/events/${e}`);
console.log(`Loaded Event ${e} Successfully`);
client.on(event.name,(args) => event.execute(client,args));
}
///////////////////////////////////////////// Registration //////////////////////////////////////////////////
var token = process.env.token;
client.once('ready', () => {
let CLIENT_ID = client.user.id;
const rest = new REST({ //obj creation for REST class
version: "9"
}).setToken(token);
(async () =>
{
try
{
if (process.env.ENV === "production")
{
await rest.put(Routes.applicationCommands(CLIENT_ID),
{
body: slash_commands_arr //arr
});
console.log("Production mode");
}
else
{
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, process.env.GUILD_ID),
{
body: slash_commands_arr, //arr
});
console.log("Maintenance mode");
}
}
catch(err)
{
console.log("An error occurred in ready() main file...Displaying it now...")
console.log(err);
}
})();
});
////////////////////////////////////////////////////////// MongoDB ///////////////////////////////////////////////////////////////
mongoose.login();
client.login(token);