-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathapp.js
More file actions
109 lines (101 loc) · 3.47 KB
/
app.js
File metadata and controls
109 lines (101 loc) · 3.47 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
const { Client, Collection } = require("discord.js");
const { readdirSync, readdir } = require("fs");
const config = require("./config.json")
const client = global.client = new Client({
intents: 32767,
presence: { activities: [{ name: config.presence.name, type: config.presence.type }] }
})
require("./structures/function")(client);
//Event Handler
const eventFiles = readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
}
client.on("messageCreate", message => {
let client = message.client;
if (message.author.bot) return;
if (message.channel.type == 'dm') return;
if (!message.content.startsWith(config.prefix)) return;
let command = message.content.split(' ')[0].slice(config.prefix.length);
let params = message.content.split(' ').slice(1);
let cmd;
if (client.commands.has(command)) {
cmd = client.commands.get(command);
}
else if (client.aliases.has(command)) {
cmd = client.commands.get(client.aliases.get(command));
}
if (cmd) {
cmd.run(client, message, params);
}
})
client.commands = new Collection();
client.aliases = new Collection();
readdir('./commands/', (err, files) => {
if (err) console.error(err);
console.log(`${files.length} adet komut yüklenecek.`);
files.forEach(f => {
let props = require(`./commands/${f}`);
console.log(`✅ Yüklenen Komut : ${props.name.toUpperCase()}`);
client.commands.set(props.name, props);
props.aliases.forEach(alias => {
client.aliases.set(alias, props.name);
});
});
});
client.reload = command => {
return new Promise((resolve, reject) => {
try {
delete require.cache[require.resolve(`./commands/${command}`)];
let cmd = require(`./commands/${command}`);
client.commands.delete(command);
client.aliases.forEach((cmd, alias) => {
if (cmd === command) client.aliases.delete(alias);
});
client.commands.set(command, cmd);
cmd.aliases.forEach(alias => {
client.aliases.set(alias, cmd.name);
});
resolve();
}
catch (e) {
reject(e);
}
});
};
client.load = command => {
return new Promise((resolve, reject) => {
try {
let cmd = require(`./commands/${command}`);
client.commands.set(command, cmd);
cmd.aliases.forEach(alias => {
client.aliases.set(alias, cmd.name);
});
resolve();
}
catch (e) {
reject(e);
}
});
};
client.unload = command => {
return new Promise((resolve, reject) => {
try {
delete require.cache[require.resolve(`./commands/${command}`)];
let cmd = require(`./commands/${command}`);
client.commands.delete(command);
client.aliases.forEach((cmd, alias) => {
if (cmd === command) client.aliases.delete(alias);
});
resolve();
} catch (e) {
reject(e);
}
});
};
client.login(config.token)