UNPKG

makecord-create

Version:

Create advanced Discord Bots with Makecord - Now with TypeScript support

107 lines (90 loc) 3.15 kB
//-------------------------------- // Thanks for using Makecord :) //-------------------------------- import { Client, GatewayIntentBits, Partials } from 'discord.js'; import { config } from 'dotenv'; import { CommandHandler } from './handlers/index.js'; import { CommandWatcher } from './utils/watcher.js'; import { startAPI } from './api/api.js'; import chalk from 'chalk'; import gradient from 'gradient-string'; import boxen from 'boxen'; // Load environment variables config(); // Pretty welcome message console.log( boxen( gradient.pastel.multiline( '⭐ Discord Bot is Starting... ⭐\n' + 'Made with Makecord 3.0.0' ), { padding: 1, margin: 1, borderStyle: 'round', borderColor: 'cyan' } ) ); // Create client instance const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers ], partials: [ Partials.Channel, Partials.Message, Partials.User, Partials.GuildMember ] }); // Initialize command handler client.commandHandler = new CommandHandler(client); // When the client is ready, run this code (only once) client.once('ready', async () => { console.log(gradient.pastel.multiline(` ╔═══════════════════════════════════════╗ ║ ║ ║ Bot is now ready! ║ ║ Made with Makecord 3.0.0 ║ ║ ║ ╚═══════════════════════════════════════╝ `)); // Load and register commands await client.commandHandler.loadCommands(); await client.commandHandler.registerCommands(); // Start REST API if enabled if (process.env.ENABLE_REST_API === 'true') { startAPI(); } // Start hot-reload if in development mode if (process.env.NODE_ENV === 'development') { const watcher = new CommandWatcher(client); watcher.start(); } console.log(chalk.cyan('\nUseful Commands:')); console.log(chalk.yellow('npm run generate') + ' - Create new commands/events'); console.log(chalk.yellow('npm run dev') + ' - Start bot with hot-reload'); }); // Handle interactions (slash commands) client.on('interactionCreate', async interaction => { await client.commandHandler.handleInteraction(interaction); }); // Handle messages (prefix commands) client.on('messageCreate', async message => { await client.commandHandler.handleMessage(message); }); // Handle errors client.on('error', error => { console.error(chalk.red('Client error:', error)); }); process.on('unhandledRejection', error => { console.error(chalk.red('Unhandled promise rejection:', error)); }); // Login to Discord client.login(process.env.TOKEN); // Export client using ES modules export { client };