A feature-rich Discord bot with slash commands, error handling, cooldowns, permissions, pagination, and more.
- Features
- Setup
- File Structure
- Configuration
- Command System
- Logging System
- Cooldowns and Permissions
- Pagination Utility
- Adding New Commands
- Deployment
- Contributing
- Slash command support
- Error handling and graceful degradation
- Cooldown system
- Permission-based command access
- Pagination for long responses
- Interactive help menu
- Moderation tools
- Logging system
- Clone the repository
- Install dependencies:
npm install
- Copy
config.example.json
toconfig.json
and fill in your bot token, client ID, and guild ID3. Copyconfig.example.json
toconfig.json
and fill in your bot token, client ID, and guild ID - Register slash commands:
node deploy-commands.js
- Start the bot:
node index.js
discord-bot/
│
├── commands/
│ ├── fun/
│ │ └── choose.js
│ ├── general/
│ │ └── help.js
│ └── moderation/
│ └── kick.js
│
├── logs/
│ ├── errors.log
│ ├── servers.log
│ ├── commands.log
│ └── server_list.log
│
├── utils/
│ └── pagination.js
│
├── config.json
├── deploy-commands.js
├── index.js
├── logger.js
└── README.md
Edit config.json
to customize the bot's behavior:
{
"token": "YOUR_BOT_TOKEN",
"clientId": "YOUR_CLIENT_ID",
"guildId": "YOUR_GUILD_ID",
"logging": {
"errors": true,
"servers": true,
"commands": true
},
"cooldowns": {
"general": 3,
"moderation": 5,
"fun": 2,
"utility": 3
},
"permissions": {
"general": "SEND_MESSAGES",
"moderation": "MODERATE_MEMBERS",
"fun": "SEND_MESSAGES",
"utility": "SEND_MESSAGES"
}
}
Commands are organized into categories (folders) within the commands/
directory. Each command is a separate file that exports an object with the following structure:
module.exports = {module.exports = {
category: 'category_name',
data: new SlashCommandBuilder()
.setName('command_name')
.setDescription('Command description'),
async execute(interaction) {
// Command logic here
},
};
The bot automatically creates a logs/
directory with the following log files:
errors.log
: Any errors encountered during bot operationservers.log
: Server join/leave eventscommands.log
: Command usageserver_list.log
: Up-to-date list of servers the bot is in
Logging can be configured in config.json
.
Cooldowns and permissions are defined in config.json
for each command category. The bot automatically applies these settings to all commands within a category.
The utils/pagination.js
file provides a utility for paginating long responses. Use it in your commands like this:
const pagination = require('../../utils/pagination');const pagination = require('../../utils/pagination');
// ... in your command's execute function:
const pages = [
new EmbedBuilder().setDescription('Page 1 content'),
new EmbedBuilder().setDescription('Page 2 content'),
// ... more pages
];
pagination(interaction, pages);
- Create a new file in the appropriate category folder within
commands/
- Use the following template:
const { SlashCommandBuilder } = require('discord.js');const { SlashCommandBuilder } = require('discord.js');
module.exports = {
category: 'category_name',
data: new SlashCommandBuilder()
.setName('command_name')
.setDescription('Command description'),
async execute(interaction) {
// Command logic here
},
};
- Run
node deploy-commands.js
to register the new command with Discord
- Ensure all your changes are committed and pushed to your repository
- Set up a hosting platform (e.g., Heroku, DigitalOcean, or a VPS)
- Configure environment variables for your bot token and other sensitive information
- Deploy your bot to the hosting platform
- Ensure the bot starts correctly and can connect to Discord
- Fork the repository
- Create a new branch:
git checkout -b feature-name
- Make your changes and commit them:
git commit -m 'Add some feature'
- Push to the branch:
git push origin feature-name
- Submit a pull request
Please ensure your code follows the existing style and includes appropriate documentation.
This project is licensed under the MIT License.