A professional Discord.js v14 bot template with support for both prefix and slash commands.
- Features
- Setup
- Usage
- Project Structure
- Adding Commands
- Available Commands
- Environment Variables
- Contributing
- License
- Support
- ✅ Discord.js v14 support
- ✅ Slash commands with automatic synchronization
- ✅ Prefix commands with aliases support
- ✅ Event handling system
- ✅ Error handling and logging
- ✅ Environment configuration
- ✅ Professional code structure
- ✅ Ready-to-use ping command (both prefix and slash)
- Node.js 16.9.0 or higher
- A Discord application and bot token
- Clone this repository:
git clone https://github.com/sw3do/discord-bot-template.git
cd discord-bot-template- Install dependencies:
npm install- Create environment file:
cp .env.example .env- Configure your
.envfile:
DISCORD_TOKEN=your_bot_token_here
CLIENT_ID=your_client_id_here
PREFIX=!
DEBUG=true- Go to Discord Developer Portal
- Create a new application
- Go to the "Bot" section and create a bot
- Copy the bot token to your
.envfile - Copy the application ID (CLIENT_ID) from the "General Information" section
Your bot needs the following permissions:
- Send Messages
- Use Slash Commands
- Read Message History
- Embed Links
npm run devnpm startsrc/
├── commands/
│ ├── prefix/ # Prefix commands
│ │ └── ping.js
│ └── slash/ # Slash commands
│ └── ping.js
├── events/ # Event handlers
│ ├── ready.js
│ └── error.js
├── utils/ # Utility functions
│ └── syncCommands.js
└── index.js # Main bot file
Create a new file in src/commands/slash/:
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('commandname')
.setDescription('Command description'),
async execute(interaction) {
await interaction.reply('Hello!');
},
};Create a new file in src/commands/prefix/:
module.exports = {
name: 'commandname',
description: 'Command description',
aliases: ['alias1', 'alias2'],
usage: 'commandname [arguments]',
async execute(message, args) {
await message.reply('Hello!');
},
};Create a new file in src/events/:
const { Events } = require('discord.js');
module.exports = {
name: Events.EventName,
once: false, // Set to true for one-time events
execute(/* event parameters */) {
// Event logic here
},
};- Slash:
/ping - Prefix:
!ping,!pong,!latency - Description: Shows bot latency and websocket heartbeat
| Variable | Description | Required |
|---|---|---|
| DISCORD_TOKEN | Your bot token | Yes |
| CLIENT_ID | Your application ID | Yes |
| PREFIX | Command prefix for prefix commands | No (default: !) |
| DEBUG | Enable debug logging | No (default: false) |
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License.
If you need help or have questions, please open an issue on GitHub.