A lightweight TypeScript npm package for building Discord bots with slash commands and modular event handling.
BotBrew is a TypeScript-based npm package designed to facilitate the development of Discord bots, with a special emphasis on slash command functionality. This lightweight library is perfect for developers looking to streamline their bot development process with an easy-to-implement solution.
Install BotBrew in your project with the following command:
npm install botbrew
To set up your bot, add the following code in your main file:
require("dotenv").config();
import { Bot } from "botbrew";
import { GatewayIntentBits } from "discord.js";
const bot = new Bot(process.env.DISCORD_TOKEN!, [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages], __dirname);
import { SlashCommand } from "botbrew";
import { ChatInputCommandInteraction } from "discord.js";
module.exports = new SlashCommand()
.setName("ping")
.setDescription("Replies with pong!")
.onExecute(async (interaction: ChatInputCommandInteraction) => {
await interaction.reply("Pong!");
});
BotBrew automatically scans the SlashCommands folder and adds these commands to your bot.
SlashCommands folder in the same scope as your main file.SlashCommands, create a subfolder for each command, e.g., echo.Folder structure for echo command with once and twice subcommands:
SlashCommands
└── echo
├── index.ts
├── once
│ └── index.ts
└── twice
└── index.ts
import {SubCommand} from "botbrew";
module.exports = new SubCommand()
.setDescription("Echoes your message!")
.addStringOption(option => option
.setName("message")
.setDescription("The message to echo")
.setRequired(true)
)
.onExecute(async (interaction) => {
await interaction.reply((interaction.options.getString("message")!));
});
import {SubCommand} from "botbrew";
module.exports = new SubCommand()
.setDescription("Echoes your message twice!")
.addStringOption(option => option
.setName("message")
.setDescription("The message to echo")
.setRequired(true)
)
.onExecute(async (interaction) => {
await interaction.reply((interaction.options.getString("message")!) + " " + (interaction.options.getString("message")!));
});
import {SlashCommand} from "botbrew";
module.exports = new SlashCommand()
.setDescription("Echoes your message!");
Note: If no command name is provided, the name of the command folder is used as the command name. In this case, the command name is echo. and the subcommands are once and twice.
BotBrew is ISC licensed.