forked from zijipia/Ziji-bot-discord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
122 lines (111 loc) · 4.07 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
require("dotenv").config();
const {
useClient,
useCooldowns,
useCommands,
useFunctions,
useGiveaways,
useConfig,
useResponder,
useWelcome,
} = require("@zibot/zihooks");
const path = require("node:path");
const { Player } = require("discord-player");
const config = useConfig(require("./config"));
const { GiveawaysManager } = require("discord-giveaways");
const { YoutubeiExtractor } = require("discord-player-youtubei");
const { loadFiles, loadEvents } = require("./startup/loader.js");
const { Client, Collection, GatewayIntentBits } = require("discord.js");
const { ZiExtractor, useZiVoiceExtractor } = require("@zibot/ziextractor");
const client = new Client({
intents: [
GatewayIntentBits.Guilds, // for guild related things
GatewayIntentBits.GuildVoiceStates, // for voice related things
GatewayIntentBits.GuildMessageReactions, // for message reactions things
GatewayIntentBits.GuildMembers, // for guild members related things
// GatewayIntentBits.GuildEmojisAndStickers, // for manage emojis and stickers
// GatewayIntentBits.GuildIntegrations, // for discord Integrations
// GatewayIntentBits.GuildWebhooks, // for discord webhooks
GatewayIntentBits.GuildInvites, // for guild invite managing
// GatewayIntentBits.GuildPresences, // for user presence things
GatewayIntentBits.GuildMessages, // for guild messages things
// GatewayIntentBits.GuildMessageTyping, // for message typing things
GatewayIntentBits.DirectMessages, // for dm messages
GatewayIntentBits.DirectMessageReactions, // for dm message reaction
// GatewayIntentBits.DirectMessageTyping, // for dm message typinh
GatewayIntentBits.MessageContent, // enable if you need message content things
],
allowedMentions: {
parse: ["users"],
repliedUser: false,
},
});
if (config.DevConfig.ai) {
const { GoogleGenerativeAI } = require("@google/generative-ai");
if (!process.env.GEMINI_API_KEY) return "No API key";
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
client.run = async (msg) => {
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
const prompt = msg;
const result = await model.generateContent(prompt);
const response = await result.response;
const text = response.text();
return text;
};
}
const player = new Player(client, {
skipFFmpeg: false,
});
player.setMaxListeners(100);
if (config.DevConfig.YoutubeiExtractor) {
player.extractors.register(YoutubeiExtractor, {});
require("youtubei.js").Log.setLevel(0);
}
if (config.DevConfig.ZiExtractor) player.extractors.register(ZiExtractor, {});
player.extractors.loadDefault((ext) => !["YouTubeExtractor"].includes(ext));
// Debug
if (config.DevConfig.DJS_DEBUG) client.on("debug", console.log);
if (config.DevConfig.DPe_DEBUG) player.events.on("debug", console.log);
if (config.DevConfig.DP_DEBUG) {
console.log(player.scanDeps());
player.on("debug", console.log);
}
useGiveaways(
config.DevConfig.Giveaway ?
new GiveawaysManager(client, {
storage: "./giveaways.json",
default: {
botsCanWin: false,
embedColor: "Random",
embedColorEnd: "#000000",
reaction: "🎉",
},
})
: () => false,
);
const ziVoice = useZiVoiceExtractor({
ignoreBots: true,
minimalVoiceMessageDuration: 1,
lang: "vi-VN",
});
const initialize = async () => {
useClient(client);
useWelcome(new Collection());
useCooldowns(new Collection());
useResponder(new Collection());
await Promise.all([
loadEvents(path.join(__dirname, "events/client"), client),
loadEvents(path.join(__dirname, "events/voice"), ziVoice),
loadEvents(path.join(__dirname, "events/process"), process),
loadEvents(path.join(__dirname, "events/player"), player.events),
loadFiles(path.join(__dirname, "commands"), useCommands(new Collection())),
loadFiles(path.join(__dirname, "functions"), useFunctions(new Collection())),
]);
client.login(process.env.TOKEN).catch((error) => {
console.error("Error logging in:", error);
console.error("The Bot Token You Entered Into Your Project Is Incorrect Or Your Bot's INTENTS Are OFF!");
});
};
initialize().catch((error) => {
console.error("Error during initialization:", error);
});