Thanks to visit codestin.com
Credit goes to github.com

Skip to content

sw3do/discord-bot-template

Repository files navigation

Discord Bot Template

License: MIT Node.js Version Discord.js GitHub issues GitHub stars

A professional Discord.js v14 bot template with support for both prefix and slash commands.

Table of Contents

Features

  • ✅ 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)

Setup

Prerequisites

  • Node.js 16.9.0 or higher
  • A Discord application and bot token

Installation

  1. Clone this repository:
git clone https://github.com/sw3do/discord-bot-template.git
cd discord-bot-template
  1. Install dependencies:
npm install
  1. Create environment file:
cp .env.example .env
  1. Configure your .env file:
DISCORD_TOKEN=your_bot_token_here
CLIENT_ID=your_client_id_here
PREFIX=!
DEBUG=true

Getting Discord Credentials

  1. Go to Discord Developer Portal
  2. Create a new application
  3. Go to the "Bot" section and create a bot
  4. Copy the bot token to your .env file
  5. Copy the application ID (CLIENT_ID) from the "General Information" section

Bot Permissions

Your bot needs the following permissions:

  • Send Messages
  • Use Slash Commands
  • Read Message History
  • Embed Links

Usage

Development

npm run dev

Production

npm start

Project Structure

src/
├── 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

Adding Commands

Slash Commands

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!');
    },
};

Prefix Commands

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!');
    },
};

Events

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
    },
};

Available Commands

Ping Command

  • Slash: /ping
  • Prefix: !ping, !pong, !latency
  • Description: Shows bot latency and websocket heartbeat

Environment Variables

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)

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

This project is licensed under the MIT License.

Support

If you need help or have questions, please open an issue on GitHub.

About

A professional Discord.js v14 bot template with support for both prefix and slash commands.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published