-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
158 lines (121 loc) · 6.6 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
const fs = require('fs');
const chalk = require('chalk');
// if (!fs.existsSync('./config.json')) require('./setup.js');
module.exports = {
dc: { // All Handlers for Discord
commands: async (path, client) => { // The Start of the command Hander
const slashcmds = []; // Create an array to store commands temporarily
client.slashcmds = [] // Create an array to store slash commands permanently
//Command Handler:
const commandFolders = fs.readdirSync(path);
for (const subfolder_file of commandFolders) {
var isd = fs.statSync(`${path}/${subfolder_file}`)
if (isd.isDirectory()) {
slashcmds.push({
name: subfolder_file,
type: 'directory',
files: fs.readdirSync(`${path}/${subfolder_file}`)
})
} else {
slashcmds.push({
name: subfolder_file,
type: 'file',
})
}
}
for (const command of slashcmds) {
if (command.type === 'directory') {
for (const file of command.files) {
const command_file = require(`${path}/${command.name}/${file}`);
if (command_file.name) {
client.slashcmds.push(command_file)
console.log(chalk.cyan(`[Commands]`) + chalk.cyan(` Loaded Slashcommand: `) + chalk.yellow(command_file.name) + chalk.cyan(` | Now Waiting for Publishing `))
} else { // If Command not has a name, then it is not a command and is not loaded into the client
console.log(chalk.cyan(`[Commands]`) + chalk.red(` ${cmd} has no name and was not loaded `))
}
}
} else {
const command_file = require(`${path}/${command.name}`);
if (command_file.name) {
client.slashcmds.push(command_file)
} else { // If Command not has a name, then it is not a command and is not loaded into the client
console.log(chalk.cyan(`[Commands]`) + chalk.red(` $No name and was not loaded `))
}
}
}
setTimeout(async () => {
await client.guilds.fetch()
var progress = 0
var failedguilds = 0
var end = false
await client.guilds.cache.forEach(async guild => {
try {
let commands = await guild.commands.set(client.slashcmds)
console.log(chalk.cyan(`[Commands]`) + chalk.cyan(` Published all Slashcommands for: `) + chalk.yellow(guild.name))
} catch (error) {
console.log(error.requestData)
failedguilds++
console.log(chalk.cyan(`[Commands]`) + chalk.red(` Failed to publish Slashcommands for ${guild.name} because ` + error))
} finally {
progress++
if (progress == client.guilds.cache.size) end = true
}
})
setTimeout(() => {
if (end && failedguilds == 0) {
console.log(chalk.cyan(`[Commands]`) + chalk.cyan(` Loaded all Slashcommands for ${client.guilds.cache.size} guilds `))
}
if (end && failedguilds > 0 && client.guilds.cache.size != failedguilds) {
console.log(chalk.cyan(`[Commands]`) + chalk.red(` Failed to publish Slashcommands for ${failedguilds} guilds. `))
} else if (end && failedguilds > 0 && client.guilds.cache.size == failedguilds) {
console.log(chalk.cyan(`[Commands]`) + chalk.red(` Failed to publish Slashcommands on all ${failedguilds} guilds. `))
}
}, 1000)
}, 5000)
},
events: async (path, client) => { // Event Handler
const events = []; // Create an array to store events temporarily
const eventFolders = fs.readdirSync(path);
for (const subfolder_file of eventFolders) {
var isd = fs.statSync(`${path}/${subfolder_file}`)
if (isd.isDirectory()) {
events.push({
name: subfolder_file,
type: 'directory',
files: fs.readdirSync(`${path}/${subfolder_file}`)
})
} else {
events.push({
name: subfolder_file,
type: 'file',
})
}
}
for (const event of events) {
if (event.type === 'directory') {
for (const file of event.files) {
const event_file = require(`${path}/${event.name}/${file}`);
if (event_file.name) {
if (event_file.once) client.once(event_file.name, (...args) => event_file.execute(...args, client));
else client.on(event_file.name, (...args) => event_file.execute(...args, client));
console.log(chalk.cyan(`[Events]`) + chalk.cyan(` Loaded Event: `) + chalk.yellow(event_file.name));
} else { // If Command not has a name, then it is not a command and is not loaded into the client
console.log(chalk.cyan(`[Events]`) + chalk.red(` ${event_file} has no name. `))
}
}
} else {
const event_file = require(`${path}/${event.name}`);
if (event_file.name) {
if (event_file.once) client.once(event_file.name, (...args) => event_file.execute(...args, client));
else client.on(event_file.name, (...args) => event_file.execute(...args, client));
console.log(chalk.cyan(`[Events]`) + chalk.cyan(` Loaded Event: `) + chalk.yellow(event_file.name));
} else { // If Command not has a name, then it is not a command and is not loaded into the client
console.log(chalk.cyan(`[Events]`) + chalk.red(` ${event_file} has no name. `))
}
}
}
},
},
other: {
}
}