Core bot components
This commit is contained in:
25
events/interactionCreate.js
Normal file
25
events/interactionCreate.js
Normal file
@@ -0,0 +1,25 @@
|
||||
require("dotenv").config();
|
||||
const { REST } = require("@discordjs/rest");
|
||||
const { Routes } = require("discord-api-types/v9")
|
||||
|
||||
module.exports = {
|
||||
name: "interactionCreate",
|
||||
async execute (interaction) {
|
||||
if (!interaction.isCommand()) return;
|
||||
|
||||
const command = interaction.client.commands.get(interaction.commandName);
|
||||
|
||||
if (!command) return;
|
||||
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
} catch (err) {
|
||||
if (err) console.log(err);
|
||||
await interaction.reply({
|
||||
content: "An error occured processing the command",
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
32
events/ready.js
Normal file
32
events/ready.js
Normal file
@@ -0,0 +1,32 @@
|
||||
require("dotenv").config();
|
||||
const { REST } = require("@discordjs/rest");
|
||||
const { Routes } = require("discord-api-types/v9")
|
||||
|
||||
module.exports = {
|
||||
name: "ready",
|
||||
once: true,
|
||||
async execute (client, commands) {
|
||||
console.log("Bot started.");
|
||||
|
||||
const CLIENT_ID = client.user.id;
|
||||
const rest = new REST({
|
||||
version: 9
|
||||
}).setToken(process.env.TOKEN);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
console.log("Registering commands...");
|
||||
if(process.env.ENV === "production") {
|
||||
await rest.put(Routes.applicationCommands(CLIENT_ID), {body: commands });
|
||||
console.log("Global commands registered");
|
||||
} else {
|
||||
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, process.env.GUILD_ID), {body: commands });
|
||||
console.log("Local commands registered");
|
||||
}
|
||||
} catch (err){
|
||||
if (err) console.log(err);
|
||||
}
|
||||
})();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user