-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
131 lines (107 loc) · 3.96 KB
/
index.js
File metadata and controls
131 lines (107 loc) · 3.96 KB
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
// Khai báo các thư viện cần thiết
const { Client, GatewayIntentBits, Collection } = require('discord.js');
const fs = require('fs');
const path = require('path');
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
let config;
try {
config = require('./config/config');
} catch (err) {
console.error('[Lỗi] Không tìm thấy file config.js, khởi động easy setup...');
return startEasySetup();
}
// Hàm kiểm tra thông tin cấu hình bắt buộc
function thieuThongTinConfig(cfg) {
// Kiểm tra các trường bắt buộc
if (!cfg.token || !cfg.clientId || !cfg.masterAdmin || !cfg.spotify?.clientSecret) return true;
if (!cfg.mongodb || !cfg.mongodb.ip || !cfg.mongodb.port || !cfg.mongodb.database) return true;
return false;
}
if (thieuThongTinConfig(config)) {
console.error('[Lỗi] Thiếu thông tin cấu hình quan trọng, khởi động easy setup...');
return startEasySetup();
}
// ==== BẮT LỖI TOÀN CỤC TRƯỚC ====
process.on("uncaughtException", (err) => {
console.error('[Lỗi toàn cục]', err);
});
// ==== KIỂM TRA INTENT BẰNG API (hiển thị ngay) ====
// ==== KHỞI ĐỘNG BOT CHÍNH ====
const { DisTube } = require('distube');
const { SpotifyPlugin } = require('@distube/spotify');
const { SoundCloudPlugin } = require('@distube/soundcloud');
const { YtDlpPlugin } = require('@distube/yt-dlp');
(async () => {
await checkIntents(config.token, config.clientId);
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
client.commands = new Collection();
client.distube = new DisTube(client, {
plugins: [
new SpotifyPlugin({
api: {
clientId: config.spotify.clientId,
clientSecret: config.spotify.clientSecret,
},
}),
new SoundCloudPlugin(),
new YtDlpPlugin({
ytdlOptions: {
highWaterMark: 1 << 25,
quality: 'highestaudio',
filter: 'audioonly',
},
}),
],
});
client.distube.setMaxListeners(10);
// Debug plugin và phiên bản
if (config.debug) {
console.log('Cấu hình truyền vào SpotifyPlugin:', config.spotify);
console.log('DisTube plugins:', client.distube.plugins?.map(p => p && p.name));
}
require('./utils/loader')(client);
client.once('ready', () => {
require('./dashboard')(client);
});
client.login(config.token);
})();
// ==== HÀM KIỂM TRA INTENT ====
async function checkIntents(token, clientId) {
const response = await fetch(`https://discord.com/api/v10/applications/${clientId}`, {
headers: { Authorization: `Bot ${token}` }
});
if (!response.ok) {
console.error('[❌] Không thể truy cập Discord API. Vui lòng kiểm tra lại token hoặc clientId.');
process.exit(1);
}
const app = await response.json();
console.log("[✔] Token hợp lệ. Bot Discord:", app.name);
console.warn("\x1b[36m[i] Lưu ý: Discord đã ngừng cập nhật 'flags' chính xác từ 2023. Kết quả kiểm tra intents có thể sai lệch.\x1b[0m");
const flags = app.flags ?? 0;
const intents = {
MESSAGE_CONTENT: (flags & (1 << 15)) !== 0,
GUILD_PRESENCES: '⚠ Không xác định (Discord không còn cung cấp flag chính xác)',
GUILD_MEMBERS: (flags & (1 << 1)) !== 0
};
for (const [intent, status] of Object.entries(intents)) {
if (status === true) {
console.log(`\x1b[32m[✔] ${intent} đã bật\x1b[0m`);
} else if (status === false) {
console.warn(`\x1b[33m[⚠] INTENT CHƯA BẬT: ${intent} — Vào Developer Portal và bật thủ công\x1b[0m`);
} else {
console.warn(`\x1b[36m[ℹ] ${intent}: ${status}\x1b[0m`);
}
}
}
// ==== EASY SETUP WEB ====
// Khởi động easy setup giao diện lấy admin ID qua Discord login
function startEasySetup() {
require('./easysetup/index');
}