Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

discbot-factory

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discbot-factory

Discord chat bot pre-builded core.

  • 2.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

DISCBOT-FACTORY

A helper tool to create discord bots with discord.js.

Pre builded modules like queue and voice. Simple implementations ways.

Creating a instance

// src/index.ts

import { Core } from "discbot-factory";

const bot: Core = new Core("<bot-name>", "<prefix>", {});

bot.authClient("<token>");

Creating commands

// src/commands/HelloWorldCommand.ts

import { ICommand, Command } from "discbot-factory";

export default class HelloWorldCommand implements ICommand {
  public readonly name: string = "hello"; // execute with <prefix>hello "!hello"
  public readonly description: string = "The hello world command";

  public execute(command: Command): void { 
    const author: string = command.message.author.username;

    command.message.channel.send(`Hello world, ${author}!`);
  }
}

Registering commands

// src/index.ts

import { Core } from "discbot-factory";

import HelloWorldCommand from "./commands/HelloWorldCommand";

const bot: Core = new Core("<bot-name>", "<prefix>", {
  commands: [new HelloWorldCommand()],
  middlewares: [],
  events: [],
});

bot.authClient("<token>");

Modules

Voice

A pre-builded voice module for create voice channel interactions.

import { Voice } from "discbot-factory";

const voice: Voice = new Voice("youtube"); // local or youtuber player.

async function playMusic(voiceChannel: VoiceChannel): Promise<void> {
  await voice.connect(voiceChannel);
  // if you are using local player, just pass the sound path.
  await voice.play("https://www.youtube.com/watch?v=mH_z5vAkf2c");

  voice.onEnd((): void => {
    console.log("Finished!");
  });
}

Queue

A queue module, nice to use with voice module and to create cool experiences like mini-games.

import { Queue } from "discbot-factory";

const queue: Queue<string> = new Queue<string>();

queue.putOnTop("hello");
queue.putOnBottom("oh no, I'm the last");

// get the first item
console.log(queue.get()) // hello

queue.removeHead();

console.log(queue.get()) // oh no, I'm the last

queue.clear();

console.log(queue.getAll()); // []

Public events

Equivalent to a client.on("event", callback) implementation.

import { IEvent, PublicEvent } from "discbot-factory";

import { Message } from "discord.js";

export default class MessageDeleteEvent implements IEvent<Message, {}, {}> {
  public readonly name: PublicEvent = PublicEvent.MESSAGE_DELETE;
  public readonly description: string = "On message delete event";

  public execute(message: Message): void {
    console.log(message.content);
  }
}

Using Middlewares

import IMiddleware from "../Core/IMiddleware";
import { Command } from "../Core/ICommand";

export default class AdminMiddleware implements IMiddleware {
  constructor(public readonly forCommands: Array<string>) {}

  public middle(command: Command): boolean {
    const username: string = command.message.author.username;

    if (username === "another dan") {
      return true;
    }

    command.message.react("🚫");
    return false;
  }
}

Keywords

FAQs

Package last updated on 07 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc