49 lines
1.8 KiB
JavaScript
49 lines
1.8 KiB
JavaScript
require("dotenv").config({ quiet: true });
|
|
const Discord = require("discord.js");
|
|
const client = new Discord.Client({
|
|
intents: [
|
|
Discord.IntentsBitField.Flags.Guilds,
|
|
Discord.IntentsBitField.Flags.GuildMembers
|
|
]
|
|
})
|
|
|
|
const bvs = require("./bvs");
|
|
|
|
|
|
const { REST, Routes } = require("discord.js");
|
|
const rest = new REST({ version: "10" }).setToken(process.env.DISCORD_TOKEN);
|
|
|
|
|
|
client.on("clientReady", () => {
|
|
console.log(`Logged in as ${client.user.tag}!`);
|
|
|
|
// Check that HOME_GUILD is set, and actually exists (as far as the client can see)
|
|
if (!process.env.HOME_GUILD) {
|
|
console.error("HOME_GUILD environment variable is not set. Please set it to the ID of the guild you want to use for testing.");
|
|
process.exit(1);
|
|
}
|
|
const homeGuild = client.guilds.cache.get(process.env.HOME_GUILD);
|
|
if (!homeGuild) {
|
|
console.error(`Could not find guild with ID ${process.env.HOME_GUILD}. Please make sure the bot is in that guild and that the ID is correct.`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const commands = require("./commands");
|
|
rest.put(Routes.applicationGuildCommands(client.user.id, process.env.HOME_GUILD), { body: commands })
|
|
.then(() => console.log("Successfully registered application commands."))
|
|
.catch(console.error);
|
|
});
|
|
|
|
client.on('interactionCreate', async interaction => {
|
|
// Check if there is a handler for the interaction in interactions/{interaction.type}/{interaction.commandName}.js, and if so, run it.
|
|
if (interaction.isChatInputCommand()) {
|
|
try {
|
|
const handler = require(`./interactions/chatCommand/${interaction.commandName}.js`);
|
|
await handler(interaction, client, bvs);
|
|
} catch (error) {
|
|
console.error(`Error handling interaction ${interaction.id}:`, error);
|
|
}
|
|
}
|
|
});
|
|
|
|
client.login(process.env.DISCORD_TOKEN); |