Git Product home page Git Product logo

24-7-radio-bot's Introduction

Discord Bot Boilerplate

Node.js Discord.js TypeScript License Issues Forks Stars

A boilerplate for building Discord bots using TypeScript, Discord.js, and Node.js.

Table of Contents

Installation

  1. Clone the repository:

    git clone https://github.com/DFanso/discord-bot-boilerplate.git
    cd discord-bot-boilerplate
  2. Install the dependencies:

    yarn install
  3. Compile the TypeScript code:

    yarn build

Configuration

Create a config.json file in the src directory with the following structure:

{
  "token": "YOUR_BOT_TOKEN",
  "clientId": "YOUR_CLIENT_ID"
}

Replace YOUR_BOT_TOKEN and YOUR_CLIENT_ID with your actual Discord bot token and client ID.

Rename .env.example file to .env and add the MONGO_URI:

MONGO_URI=mongodb+srv://<username>:<password>@cluster0.mongodb.net/<dbname>?retryWrites=true&w=majority

Usage

To start the bot, run:

yarn start

This will use nodemon to watch for file changes and automatically restart the bot.

Project Structure

discord-bot-boilerplate/
├── src/
│   ├── commands/
│   │   └── exampleCommand.ts
│   ├── events/
│   │   └── ready.ts
│   ├── services/
│   │   └── UserService.ts
|   ├── models/
│   │   └── user.ts
│   ├── dto/
│   │   └── UserDTO.ts
│   ├── utils/
|   |   └── deploy.ts
│   │   └── database.ts
│   ├── config.json
│   └── index.ts
├── package.json
├── tsconfig.json
└── nodemon.json
  • commands/: Directory for command files.
  • events/: Directory for event files.
  • services/: Directory for additional services.
  • dtos/: Directory for Data Transfer Objects.
  • utils/: Directory for utility files, such as database connection.
  • config.json: Configuration file containing the bot token and client ID.
  • index.ts: Entry point of the bot.

Commands and Events

  • Commands are stored in the src/commands directory and must export a data property with command metadata and an execute function.
  • Events are stored in the src/events directory and must export a name and execute function.

Example Command (src/commands/exampleCommand.ts)

import { CommandInteraction } from 'discord.js';

module.exports = {
  data: {
    name: 'example',
    description: 'Example command'
  },
  async execute(interaction: CommandInteraction) {
    await interaction.reply('Hello from the example command!');
  }
};

Example Event (src/events/ready.ts)

import { Client } from 'discord.js';

module.exports = {
  name: 'ready',
  once: true,
  execute(client: Client) {
    console.log(`${client.user?.tag} is online!`);
  }
};

Contributing

Contributions are welcome! Please create a pull request or open an issue to discuss your ideas.

License

This project is licensed under the MIT License. See the LICENSE file for details.

24-7-radio-bot's People

Contributors

dfanso avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.