-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
114 lines (99 loc) · 2.96 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
const {
REST
} = require('@discordjs/rest');
const {
Routes
} = require('discord-api-types/v9');
const {
Client,
Intents,
MessageActionRow,
MessageButton,
MessageEmbed,
Collection,
MessageSelectMenu,
Modal,
TextInputComponent,
showModal
} = require("discord.js");
const config = require("./config.json");
const {
readdirSync
} = require("fs");
const client = new Client({
intents: 32767
});
client.login(config.token);
client.on("ready", async () => {
console.log("Hazır");
});
// Buton Etkileşimleri
client.buttonInteractions = new Collection();
readdirSync("./buttonInteractions/").forEach(f => {
let cmd = require(`./buttonInteractions/${f}`);
client.buttonInteractions.set(cmd.customId, cmd);
});
// Buton Etkileşimleri
// Modal Etkileşimleri
client.modalInteractions = new Collection();
readdirSync("./modalInteractions/").forEach(f => {
let cmd = require(`./modalInteractions/${f}`);
client.modalInteractions.set(cmd.customId, cmd);
});
// Modal Etkileşimleri
// Select Menu Etkileşimleri
client.selectMenuInteractions = new Collection();
readdirSync("./selectMenuInteractions/").forEach(f => {
let cmd = require(`./selectMenuInteractions/${f}`);
client.selectMenuInteractions.set(cmd.customId, cmd);
});
// Select Menu Etkileşimleri
// Context Menu Etkileşimleri
client.contextMenuInteractions = new Collection();
readdirSync("./contextMenuInteractions/").forEach(f => {
let cmd = require(`./contextMenuInteractions/${f}`);
client.contextMenuInteractions.set(cmd.customId, cmd);
});
// Context Menu Etkileşimleri
// Slash Etkileşimleri
client.slashInteractions = new Collection();
let globalSlashCommands = [];
readdirSync("./slashInteractions/").forEach(f => {
let cmd = require(`./slashInteractions/${f}`);
client.slashInteractions.set(cmd.name, cmd);
globalSlashCommands.push(cmd.command);
});
// Slash Etkileşimleri
// Events'ları çekelim
readdirSync("./events/").forEach(f => {
let event = require(`./events/${f}`);
client.on(`${event.name}`, (...args) => {
event.run(...args);
});
});
// Events'ları çekelim
// Slash Global Komutlar Ekleyelim
let rest = new REST({
version: '9'
}).setToken(config.token);
client.on("ready", async () => {
try {
await rest.put(
Routes.applicationCommands(client.user.id), {
body: globalSlashCommands
},
);
console.log('Global komutlar güncellendi.');
} catch (error) {
console.error(error);
};
});
// Slash Global Komutlar Ekleyelim
client.on("interactionCreate", async int => {
if (int.isCommand()) client.slashInteractions.get(int.commandName)?.run(client, int);
else if (int.isContextMenu()) client.contextMenuInteractions.get(int.customId)?.run(client, int);
else if (int.isSelectMenu()) client.selectMenuInteractions.get(int.customId)?.run(client, int);
else if (int.isModalSubmit()) client.modalInteractions.get(int.customId)?.run(client, int);
else if (int.isButton()) client.buttonInteractions.get(int.customId)?.run(client, int);
else console.log("Bilinmeyen interaction: " + int.customId);
});