Files
.gitignore
bot.js
package.json
Code
3 63
bot.js
const { Client, GatewayIntentBits } = require('discord.js');
require('dotenv').config();
const token = process.env.DISCORD_TOKEN;
if (!token || token === 'your_discord_bot_token_here') {
throw new Error('Set your Discord bot token in the .env file as DISCORD_TOKEN.');
}
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const helpMessage = '# /Help\n\nAny Help needed can be handled in tickets by our\nstaff members you can also ask for help in General\n-# This is a Premade Message';
client.once('clientReady', async () => {
try {
await client.application.commands.set([
{ name: 'Help', description: 'Get help from the SMP Portal staff' }
]);
console.log(`Bot is ready! Logged in as ${client.user.tag}`);
console.log('KODARI_READY');
} catch (error) {
console.error('Failed to register slash commands:', error);
}
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand() || interaction.commandName.toLowerCase() !== 'help') return;
try {
await interaction.reply({ content: helpMessage });
} catch (error) {
console.error('Failed to respond to /Help:', error);
if (interaction.deferred || interaction.replied) {
await interaction.followUp({ content: 'An error occurred while handling this command.', ephemeral: true }).catch(console.error);
} else {
await interaction.reply({ content: 'An error occurred while handling this command.', ephemeral: true }).catch(console.error);
}
}
});
client.on('error', (error) => {
console.error('Discord client error:', error);
});
client.login(token).catch((error) => {
console.error('Failed to log in to Discord:', error);
process.exitCode = 1;
});