-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
73 lines (61 loc) · 1.94 KB
/
app.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
const fs = require("fs");
const { Client, Intents, MessageActionRow, MessageButton, MessageEmbed, Collection, ModalBuilder, TextInputBuilder, TextInputStyle, InteractionType } = require("discord.js");
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const dotenv = require("dotenv");
dotenv.config({ path: "./.env" });
const client = new Client({
fetchAllMembers: true,
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_BANS,
Intents.FLAGS.GUILD_INTEGRATIONS,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
],
});
const mongoose = require("mongoose");
mongoose
.connect(process.env.mongoDB)
.then(() => console.log("MongoDB connected!"))
.catch((err) => console.log(err));
global.client = client;
client.commands = (global.commands = []);
fs.readdir("./letKomutlar/", (err, files) => {
if (err) throw err;
files.forEach((file) => {
if (!file.endsWith(".js")) return;
const props = require(`./letKomutlar/${file}`);
client.commands.push({
name: props.name.toLowerCase(),
description: props.description,
options: props.options,
category: props.category,
});
console.log(`Command Loaded: ${props.name}`);
});
});
fs.readdir("./events/", (_err, files) => {
files.forEach((file) => {
if (!file.endsWith(".js")) return;
const event = require(`./events/${file}`);
const eventName = file.split(".")[0];
console.log(`Event Loaded: ${eventName}`);
client.on(eventName, (...args) => {
event(client, ...args);
});
});
});
client.on("ready", async () => {
const rest = new REST({ version: "9" }).setToken(process.env.token);
try {
await rest.put(Routes.applicationCommands(client.user.id), {
body: client.commands,
});
} catch (error) {
console.error(error);
}
});
client.login(process.env.token);