This repository has been archived by the owner on Nov 12, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (73 loc) · 2.67 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
// Discord Imports
const {Client, GatewayIntentBits, Collection} = require("discord.js");
const {REST} = require("@discordjs/rest");
const { Routes } = require('discord-api-types/v9')
const {readdirSync} = require("fs");
const fs = require("fs");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildWebhooks
]
});
// Discord CommandHandler
const slashCommandsFiles = fs.readdirSync("./commands/slashCommands").filter(file => file.endsWith('.js'));
const commands = [];
client.commands = new Collection();
try {
for (const file of slashCommandsFiles) {
const command = require(`./commands/slashCommands/${file}`);
commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
console.log("SlashCommands pushed")
}
} catch (e) {
console.log("There was an error while set the SlashCommand Files\n"+e)
console.log(slashCommandsFiles)
console.log("---------------")
}
// dotenv import
require("dotenv").config();
const config = require("./config.json");
// onReady Statement
client.on("ready", async () => {
console.log("Logged in as "+client.user.username);
// SlashCommands registering
const rest = new REST({version: '10' }).setToken(process.env.TOKEN);
await(async () => {
try {
await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID), {
body: commands
}
);
console.log("SlashCommands registered\n")
console.log(commands);
} catch (e) {
console.error("There was an error registering SlashCommands!")
}
})();
})
// Client InteractionCreate Statement
client.on("interactionCreate", async interaction => {
try {
if(!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if(!command) return;
await command.run(interaction, client, config);
} catch (e) {
console.error("There was an error executing the SlashCommand!\n"+e)
}
})
// Client Login
client.login(process.env.TOKEN);