A modern Discord bot template built with TypeScript and Discord.js v14, featuring a modular command system and comprehensive development setup.
- TypeScript Support: Full TypeScript setup with strict type checking
- Discord.js v14: Latest Discord.js with slash commands support
- Modular Commands: Easy-to-extend command handler system
- Environment Configuration: Secure environment variable management
- Hot Reload: Development server with automatic restarts
- Example Commands: Pre-built commands to get you started
- Email Integration: Nodemailer with OVH SSL support
- Error Handling: Comprehensive error handling and logging
- Modern ES2022: Latest JavaScript features and syntax
-
Clone and install dependencies:
npm install
-
Set up environment variables:
copy .env.example .env
-
Configure your bot: Edit
.envfile with your Discord bot credentials and email settings:# Discord Configuration DISCORD_TOKEN=your_bot_token_here DISCORD_CLIENT_ID=your_client_id_here DISCORD_GUILD_ID=your_guild_id_here # Optional, for faster command registration during development # Email Configuration (OVH) EMAIL_HOST=ssl0.ovh.net EMAIL_PORT=465 EMAIL_SECURE=true EMAIL_USER=your_email@yourdomain.com EMAIL_PASSWORD=your_email_password_here EMAIL_FROM="Your Name <your_email@yourdomain.com>"
- Go to Discord Developer Portal
- Create a new application
- Go to "Bot" section and create a bot
- Copy the bot token to
DISCORD_TOKEN - Go to "General Information" and copy Application ID to
DISCORD_CLIENT_ID - For guild ID, right-click your Discord server and "Copy Server ID" (requires Developer Mode enabled)
# Start development server with hot reload
npm run dev
# Build the project
npm run build
# Start production server
npm start
# Lint code
npm run lint
# Format code
npm run formatsrc/
├── commands/ # Slash commands
│ ├── ping.ts # Ping command with latency
│ ├── info.ts # Bot information
│ └── hello.ts # Greeting command with options
├── handlers/ # Event and command handlers
│ └── commandHandler.ts
├── types/ # TypeScript type definitions
│ └── command.ts
├── utils/ # Utility functions
│ ├── sendEmail.ts # Email functionality with OVH SSL
│ └── fetchGoogleSheet.ts
├── config.ts # Configuration management
├── index.ts # Main bot file
└── emailTest.ts # Email testing utilities
- Create a new file in
src/commands/(e.g.,mycommand.ts) - Follow this template:
import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js';
import { Command } from '../types/command';
const myCommand: Command = {
data: new SlashCommandBuilder()
.setName('mycommand')
.setDescription('My awesome command!'),
async execute(interaction: ChatInputCommandInteraction) {
await interaction.reply('Hello from my command!');
},
};
export default myCommand;- The command will be automatically loaded and registered!
The project includes a robust email utility using Nodemailer with OVH SSL configuration:
import { sendEmail, sendSimpleEmail, sendHtmlEmail } from './utils/sendEmail';
// Simple text email
await sendSimpleEmail(
'recipient@example.com',
'Subject',
'Your message here'
);
// HTML email with fallback
await sendHtmlEmail(
'recipient@example.com',
'HTML Subject',
'<h1>Hello!</h1><p>HTML content</p>',
'Plain text fallback'
);
// Advanced email with multiple recipients
await sendEmail({
to: ['user1@example.com', 'user2@example.com'],
cc: 'manager@example.com',
subject: 'Advanced Email',
html: '<p>Your HTML content</p>',
text: 'Fallback text',
attachments: [
{
filename: 'document.pdf',
path: '/path/to/document.pdf'
}
]
});Run the email test suite:
npm run dev-test && node dist/emailTest.js/ping- Shows bot latency and websocket heartbeat/info- Displays bot information and statistics/hello [user] [message]- Greets a user with optional custom message
- Slash Command Support: Modern Discord slash commands
- Auto-registration: Commands are automatically registered with Discord
- Type Safety: Full TypeScript support for all interactions
- Error Handling: Graceful error handling with user feedback
- Development & Production: Different registration modes for faster development
| Variable | Description | Required |
|---|---|---|
DISCORD_TOKEN |
Your bot's token | ✅ |
DISCORD_CLIENT_ID |
Your application's client ID | ✅ |
DISCORD_GUILD_ID |
Guild ID for faster command registration | ❌ |
EMAIL_HOST |
SMTP server hostname (default: ssl0.ovh.net) | ✅ |
EMAIL_PORT |
SMTP server port (default: 465) | ✅ |
EMAIL_SECURE |
Use SSL/TLS (default: true) | ✅ |
EMAIL_USER |
Your email address | ✅ |
EMAIL_PASSWORD |
Your email password | ✅ |
EMAIL_FROM |
From address with display name | ✅ |
NODE_ENV |
Environment mode (development/production) | ❌ |
-
Build the project:
npm run build
-
Set environment variables on your hosting platform
-
Start the bot:
npm start
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the ISC License.
If you need help:
- Check the Discord.js Guide
- Join the Discord.js Discord Server
- Review the Discord Developer Documentation
Happy coding! 🎉