-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
131 lines (106 loc) · 4.2 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
123
124
125
126
127
128
129
130
131
const fs = require("fs");
const db = require('quick.db')
const fetch = require('node-fetch')
const { REST } = require("@discordjs/rest");
const { Client, GatewayIntentBits, ActivityType, Collection, EmbedBuilder, Routes, Partials, Colors } = require("discord.js");
const { token, DevelopmentServerId, type } = require("./config.json");
const { no_perms, error_embed } = require("./responses.json");
const Discord = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds
],
partials: [Partials.Channel]
})
const commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"))
const commands = [];
client.commands = new Collection();
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
}
client.on("error", console.error);
process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
});
client.once('ready', async() => {
console.clear();
console.log("Bot Online");
console.log("Logged in as:", client.user.tag)
const CLIENT_ID = client.user.id;
const rest = new REST({
version: "10"
}).setToken(token);
(async () => {
try {
if (type === "production") {
await rest.put(Routes.applicationCommands(CLIENT_ID), {
body: commands
});
console.log("Commands have been added to Global Usage.")
} else {
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, DevelopmentServerId), {
body: commands
})
console.log(`Commands have been added as Guild Only Usage.`)
}
} catch (err) {
console.error(err);
}
})();
client.user.setPresence({
activities: [{ name: `keyauth.cc`, type: ActivityType.Competing }],
status: 'online',
});
});
client.on('interactionCreate', async interaction => {
if (!interaction.type === 2) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
await interaction.deferReply({ ephemeral: true });
if(interaction.member != null)
if(!interaction.member.roles.cache.find(x => x.name == "perms")) return interaction.editReply({ embeds: [new Discord.EmbedBuilder().setDescription(no_perms.response[interaction.locale] || no_perms.response['default']).setColor(Colors.Red).setTimestamp()], ephemeral: true})
const ErrorEmbed = new EmbedBuilder()
.setAuthor({ name: "Interaction Failed" })
.setColor(Colors.Red)
.setTimestamp()
.setFooter({ text: "KeyAuth Discord Bot", iconURL: client.user.displayAvatarURL()})
client.user.setPresence({
activities: [{ name: `keyauth.cc`, type: ActivityType.Competing }],
status: 'online',
});
let idfrom = null;
if(interaction.guild == null)
idfrom = interaction.user.id;
else
idfrom = interaction.guild.id;
let content = `**${interaction.user.username}#${interaction.user.discriminator} (ID: ${interaction.user.id})** executed the command \`/${interaction.commandName}\`\n`;
for (var i = 0; i < interaction.options._hoistedOptions.length; i++) {
content += "\n" + interaction.options._hoistedOptions[i].name + " : " + interaction.options._hoistedOptions[i].value;
}
let wh_url = await db.get(`wh_url_${idfrom}`)
if(wh_url != null) {
var params = {
// content: `**${interaction.user.username}#${interaction.user.discriminator} (ID: ${interaction.user.id})** executed the command \`/${interaction.commandName}\`\n\nwith the paramaters:\`${JSON.stringify(interaction.options._hoistedOptions)}\``
content: content
}
fetch(wh_url, {
method: "POST",
headers: {
'Content-type': 'application/json'
},
body: JSON.stringify(params)
})
}
try {
await command.execute(interaction);
} catch(err) {
if (err) console.error(err);
await interaction.editReply({
embeds: [ErrorEmbed],
ephemeral: true
})
}
});
client.login(token);