-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (69 loc) · 2.68 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
require("dotenv").config()
const { Client, Collection } = require("guilded.js")
const { PermaDB } = require("perma.db")
const path = require("path")
const fs = require("fs")
const os = require("os")
const consoled = require("consoled.js")
const config = require("./config.json")
const cache = require("./modules/cache")
const db = new PermaDB('perma.db', { minimize: true, memory: false, });
const log = require("./modules/log")
consoled.bright.white("--------------------------------------------")
consoled.bright.white("https://github.com/Rednexie/guilded-template")
consoled.bright.white("--------------------------------------------")
let banned;
banned = db.getSync("banned");
banned = banned !== null ? JSON.parse(banned) : []
banned.forEach(ban => {
cache.set(`ban@${ban}`, true)
})
const token = process.env.TOKEN || config.token
const client = new Client({
token,
prefix: config.prefix,
intents: ["GUILDS", "MESSAGES"],
cache: {
channels: true,
messages: true,
users: true,
roles: true,
teams: true,
members: true,
},
});
try{
client.login(token)
}
catch(error){
consoled.bright.red("client login error, please check your token and client.") && process.exit(1)
}
client.commands = new Collection();
client.slashes = new Collection()
client.aliases = new Collection();
const commandFiles = fs.readdirSync("./commands/").filter(file => file.endsWith(".js"));
for(command of commandFiles){
const cmd = require(`./commands/${command}`);
if(cmd && cmd.config?.name) client.commands.set(cmd.config.name, cmd);
}
const eventFiles = fs.readdirSync("./events/").filter(file => file.endsWith(".js"))
for(event of eventFiles){
const ev = require(`./events/${event}`);
if(ev.config.once){
client.once(ev.config.name, (...args) => ev.execute(...args, client))
}
else{
client.on(ev.config.name, (...args) => ev.execute(...args, client))
}
}
const commandSubFolders = fs.readdirSync("./commands/").filter(folder => !folder.endsWith(".js") && fs.statSync(`./commands/${folder}`).isDirectory())
for(folder of commandSubFolders){
const commandSubFolderFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith(".js"))
for(command of commandSubFolderFiles){
const cmd = require(`./commands/${folder}/${command}`)
client.commands.set(cmd.config.name, cmd)
}
}
consoled.green(`${commandFiles.length} bot ${commandFiles.length > 1 ? "commands" : "command"} loaded.`)
consoled.green(`${commandSubFolders.length} command ${commandSubFolders.length > 1 ? "subfolders" : "subfolder"} readed.`)
consoled.green(`${eventFiles.length} event ${eventFiles.length > 1 ? "listeners" : "listener"} activated.`)