Skip to content

Message Commands

Message commands let your bot react to specific text patterns in chat, like replying when someone says “Hello Bight”. They’re provided through @bight-ts/plugin-message-commands as an opt-in extra.

src/message-commands/hello.ts
import { defineMessageCommand } from "@bight-ts/plugin-message-commands";
export const helloMessageCommand = defineMessageCommand({
data: {
name: "hello-bight",
description: "Reply when someone says hello.",
},
match: ({ message }) => message.content.toLowerCase() === "hello bight",
async execute({ message }) {
await message.reply("Hello from Bight.");
},
});

The match function acts as a filter. execute only runs when match returns true.

src/plugins/message-commands.ts
import { createMessageCommandsPlugin } from "@bight-ts/plugin-message-commands";
import { helloMessageCommand } from "../message-commands/hello";
export const messageCommandsPlugin = createMessageCommandsPlugin({
commands: [helloMessageCommand],
});

Add the plugin to src/plugins/index.ts.

Like prefix commands, message commands need the GuildMessages and MessageContent intents enabled. See Gateway Intents.

Message commands run through the same precondition and diagnostics pipeline as slash commands.