Cordmand
About
A utility package for making discord-bot commands much easier to write with discord.js.
Usage Example
Install this package:
npm i @reinforz/cordmand
or,
yarn add @reinforz/cordmand
Example typescript file:
import { Client, GatewayIntentBits } from "discord.js";
import { addCommands } from "@reinforz/cordmand";
import { Commands } from "@reinforz/cordmand/types";
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
const commands: Commands = {
interactionCreate: [
{
name: "ping",
cb: async (interaction) => {
await interaction.reply("Pong!");
},
},
{
name: "hello",
message: {
content: "hello",
ephemeral: true,
},
},
],
messageCreate: [
{
regex: /ping/i,
message: "pong",
},
{
regex: /hi/i,
message: (_, message) => `hello <@${message.author.id}>`,
},
{
regex: /bye/i,
message: (_, message) => `bye ${message.author.username}`,
reply: true,
},
{
regex: /args/i,
message: (args) => `The arguments are: ${args.join(", ")}`,
reply: true,
},
],
};
addCommands(client, commands, {
messageCommandPrefix: /^i!/i,
});
client.login(process.env.BOT_TOKEN!);
Example with just using makeDiscordClient
function:
import { makeDiscordClient } from "@reinforz/cordmand";
import { Commands, MakeDiscordClientOptions } from "@reinforz/cordmand/types";
import { commands } from "./some-file"
const makeClientOptions: MakeDiscordClientOptions = {
botToken: process.env.BOT_TOKEN!,
clientOptions: {
intents: ["Guilds", "GuildMessages", "MessageContent", "GuildMembers"],
},
commands,
addCommandsOptions: {
messageCommandPrefix: /^i!/i,
},
};
makeDiscordClient(makeClientOptions);
Contributors