Skip to content
This repository was archived by the owner on May 30, 2020. It is now read-only.

RedDaedalus/discord.js-base-class

Repository files navigation

discord.js-base-class

Warning: This is highly out of date, and will not work with newer discord.js versions, and has some pretty serious dependency security issues. V2 is coming out soon. A simple base class for discord.js bots.

Setup

Almost everything is already set up, so getting started isn't very complicated. The current configuration is designed to have a config file named config.json with the token property set your bot's token. There currently isn't support for server by server configuration, but that is to be expected shortly.

Creating commands

This is a simple example of a ping command's code. Put command files in the commands folder by default.

// Import base command
const Base = require("../base/Command");

// Create a class for the command that extends the base command
 class Ping extends Base {
  constructor(client) {
    // Initialise base command and pass data - all properties except name are optional
    super(client, {
      name: "ping",
      description: "Pings the bot.",
      usage: "", // Usage does not include the command - it is simply the arguments passed
      category: "Information",
      cooldown: 1000,
      aliases: ["pong"],
      // permLevel is interchangable with permission, although you can have both
      permLevel: 0,
      permission: "READ_MESSAGES"
    });
  }
  
  run(message, args) {
    // Respond with the time between now and when the user sent their message
    super.respond(`Pong! Took ${Date.now() - message.createdAt}ms.`);
  }
}

// Export the class
module.exports = Ping;

Registering events

There will register an event. Put events in the events folder by default. Events do not have a name property - the name will be fetched from the file name.

// Create a class for the event
class Error {
  constructor(client) {
    this.client = client;
  }
  
  run(error) {
    console.log(`Websocket error:\n${error}`);
  }
}

// Export the class
module.exports = Error;

About

A simple base class for discord.js bots.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published