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
import { Core } from "discbot-factory";
const bot: Core = new Core("<bot-name>", "<prefix>", {});
bot.authClient("<token>");
Creating commands
import { ICommand, Command } from "discbot-factory";
export default class HelloWorldCommand implements ICommand {
public readonly name: string = "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
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");
async function playMusic(voiceChannel: VoiceChannel): Promise<void> {
await voice.connect(voiceChannel);
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");
console.log(queue.get())
queue.removeHead();
console.log(queue.get())
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;
}
}