This repository has been archived by the owner on Dec 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
181 lines (148 loc) · 5.18 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
const Discord = require("discord.js");
const fs = require("fs");
const dotenv = require("dotenv");
dotenv.config();
"use strict";
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.GuildModeration,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.MessageContent,
],
});
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
client.categories = fs.readdirSync(`./comandosPrefix/`);
fs.readdirSync("./comandosPrefix/").forEach((local) => {
const comandos = fs
.readdirSync(`./comandosPrefix/${local}`)
.filter((arquivo) => arquivo.endsWith(".js"));
for (let file of comandos) {
let puxar = require(`./comandosPrefix/${local}/${file}`);
if (puxar.name) {
client.commands.set(puxar.name, puxar);
}
if (puxar.aliases && Array.isArray(puxar.aliases))
puxar.aliases.forEach((x) => client.aliases.set(x, puxar.name));
}
});
client.on("messageCreate", async (message) => {
if (message.author.bot) return;
if (message.channel.type === Discord.ChannelType.DM) return;
const serverId = message.guild.id;
const db = client.mongoClient.db("configs");
const collection = db.collection("servers");
try {
const result = await collection.findOne({ server_id: serverId });
if (result) {
const prefix = result.custom_prefix || process.env.PREFIX;
if (!message.content.toLowerCase().startsWith(prefix.toLowerCase()))
return;
if (!message.content.startsWith(prefix)) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
if (cmd.length === 0) return;
let command = client.commands.get(cmd);
if (!command) command = client.commands.get(client.aliases.get(cmd));
try {
command.run(client, message, args);
} catch (err) {
console.error("Erro:" + err);
}
} else {
const prefix = process.env.PREFIX;
if (!message.content.toLowerCase().startsWith(prefix.toLowerCase()))
return;
if (!message.content.startsWith(prefix)) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
if (cmd.length === 0) return;
let command = client.commands.get(cmd);
if (!command) command = client.commands.get(client.aliases.get(cmd));
try {
command.run(client, message, args);
} catch (err) {
console.error("Erro:" + err);
}
}
} catch (error) {
console.error("Erro ao consultar o banco de dados:", error);
}
});
module.exports = client;
function getTotalMembers() {
return client.guilds.cache.reduce((total, guild) => total + guild.memberCount, 0);
}
client.on("ready", () => {
console.log(
`🔥 Estou online em ${client.guilds.cache.size} Servidores!\n🎈 Estou logado(a) como ${client.user.tag}!`,
);
client.user.setStatus("online");
let status = [
{
name: "🎁Confira meu site: https://flextux.pages.dev",
type: Discord.ActivityType.Playing,
},
{
name: `💻${client.guilds.cache.size} Servidores`,
type: Discord.ActivityType.Playing,
},
{
name: `🎇${getTotalMembers()} Usuários`,
type: Discord.ActivityType.Playing,
},
{
name: "🎉Confira meu perfil no Top.gg",
type: Discord.ActivityType.Playing,
},
{
name: "💎Veja meus comandos usando /ajuda.",
type: Discord.ActivityType.Playing,
},
];
client.user.setActivity(status[0]);
setInterval(() => {
let random = Math.floor(Math.random() * status.length);
client.user.setActivity(status[random]);
}, 120000);
//setTimeout(() => {
// const { AutoPoster } = require('topgg-autoposter')
// const ap = AutoPoster(process.env.TOP_GG_TOKEN, client)
// ap.on('posted', () => {
// })
//}, 6000000);
});
process.on("multipleResolutions", (type, reason, promise) => {
console.log(`🚫 Erro Detectado\n\n` + type, promise, reason);
});
process.on("unhandledRejection", (reason, promise) => {
console.log(`🚫 Erro Detectado:\n\n` + reason, promise);
});
process.on("uncaughtException", (error, origin) => {
console.log(`🚫 Erro Detectado:\n\n` + error, origin);
});
process.on("uncaughtExceptionMonitor", (error, origin) => {
console.log(`🚫 Erro Detectado:\n\n` + error, origin);
});
fs.readdir("./eventos", (err, file) => {
file.forEach((event) => {
require(`./eventos/${event}`);
});
});
client.slashCommands = new Discord.Collection();
require("./handler")(client);
client.login(process.env.DISCORD_TOKEN);
const { MongoClient } = require("mongodb");
const uri = process.env.MONGODB_URI;
const clientMongo = new MongoClient(uri);
clientMongo
.connect()
.then(() => {
console.log("📚 Conectado ao MongoDB!");
})
.catch((error) => {
console.error("Ocorreu um erro ao conectar ao MongoDB:", error);
});
module.exports.mongoClient = clientMongo;