Giter Club home page Giter Club logo

ts-discord-bot-boilerplate's Introduction

ts-discord-bot-boilerplate

Get started with a new Discord bot using discord.js fast.

Usage

This section contains information about where to define new functionality for your Discord bot.

Events

Trigger actions on a new event by adding a new file that has the same name as a specific event name defined in the event section of the documentation.

To properly initialize the event, this file has to be added to the event directory you specified in the configuration file of the bot: config.ts.

Example of Event: Ready

Ready.ts

import { Client } from '../Client';
import { Logger } from '../utils/Logger';
import { BotEvent } from '../types';

export default class Ready implements BotEvent {
    public client: Client;

    constructor(client: Client) {
        this.client = client;
    }

    public async run(): Promise<void> {
        Logger.info('Execute an action when the Ready event is triggered');
    }
}

Commands

Execute commands when a specific keyword including the command prefix has been sent in a Discord channel.

To properly initialize the command, this file has to be added to the command directory you specified in the configuration file of the bot: config.ts.

Example of Command: Ping

Ping.ts

import { Message } from 'discord.js';
import { Command } from '../Command';
import { BotClient } from '../types';

export default class Ping extends Command {
    constructor(client: BotClient) {
        super(client, {
            name: 'ping',
            description: 'Pings the bot.',
            category: 'Information',
            usage: client.settings.prefix.concat('ping'),
            cooldown: 1000,
            requiredPermissions: ['SEND_MESSAGES']
        });
    }

    public async run(message: Message): Promise<void> {
        await super.respond(message.channel, 'Pong!');
    }
}

Running

To run the bot, first create an application on the Discord developer portal. Then copy the .env.example and rename it into .env. A proper .env file should look like this:

.env

BOT_TOKEN=RANDOMTOKENYOURECEIVEDFROMTHEDEVELOPERPORTAL

After everything is configured, you can run the bot locally by executing the npm start command.

Documentation

During development, refer to the documentation served by discord.js.

License

MIT

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.