Commands and events
Add slash commands, typed options, replies, and Discord event handlers.
Commands respond to Discord slash command invocations. Events respond to Discord activity such as messages, member changes, reactions, and voice state updates.
Slash command options
Define options once and reuse the same object in the command generic. That makes ctx.event.options match the command definition.
import {
,
,
,
} from "itsmybot";
export const = ({
: ({
: "Who should receive the preview",
: true,
: 1,
: 32,
}),
: ({
: "Post publicly instead of an ephemeral reply",
}),
});
.target.required;Available option builders:
stringOptionintegerOptionnumberOptionbooleanOptionuserOptionchannelOptionroleOptionmentionableOptionattachmentOption
Command class
ctx.reply() returns a Discord command reply action. Use ephemeral for private output.
import { , type } from "itsmybot";
import type { Config } from "../config";
import { } from "./options";
export class extends <Config, typeof > {
readonly = "preview";
readonly = "Preview configured output";
readonly = ;
(: <Config, typeof >) {
...target; return .(
`${..}, ${...}`,
{ : !... },
);
}
}Command reply helpers available on command context:
ctx.reply(content, { ephemeral })ctx.deferReply({ ephemeral })ctx.editReply(content)ctx.followUp(content, { ephemeral })ctx.deleteReply()
Declare PluginCapability.DiscordInteractionReply when a plugin uses command reply actions.
Message events
Use event handlers when the plugin reacts outside slash commands.
import {
,
type ,
} from "itsmybot";
import type { Config } from "../config";
export class extends <Config> {
(: <Config>) {
return ..;
}
(: <Config>) {
..mentionReply; return .(..);
}
}Declare PluginCapability.DiscordMessageWrite when an event sends a message.
Returning multiple actions
Use ctx.ok() when you need to return actions and logs together.
import { , type } from "itsmybot";
import type { Config } from "./config";
function (: <Config>) {
return .([
(.., ..),
], [
.(`Sent mention reply in ${..}.`),
]);
}Event types
Specialized event classes exported by the SDK:
InteractionCreateEventMessageCreateEventGuildMemberAddEventGuildMemberRemoveEventMessageReactionAddEventVoiceStateUpdateEvent
Prefer specialized classes over raw event name strings. They give the handler the correct context type.