Little recipes
A few patterns you can lift into your bot.
These are small ideas you can copy and adapt. Each assumes you already have the quick start running.
A private slow command
Set deferReply before doing work that might outlast Discord's initial interaction window:
const summary = {
type: CommandType.SLASH,
description: "Build a private summary",
deferReply: { ephemeral: true },
callback: async () => ({ content: await buildSummary() }),
} satisfies CommandObject;A command only the bot owner can use
Pass your Discord user ID in botOwners and add the flag:
const swag = await SWAG.create({ client, botOwners: ["YOUR_USER_ID"] });
// On a command:
ownerOnly: true,The guard runs before the callback. Add guildOnly: true if the command makes no sense in DMs.
A test-server-only slash command
const swag = await SWAG.create({
client,
commandsDir: "./dist/commands",
testServers: ["YOUR_TEST_GUILD_ID"],
});
// On a slash command:
testOnly: true,
// After the client is ready:
await swag.deployCommands({ scope: "test" });A testOnly command is deployed to the configured guilds and guarded at runtime. When you promote it to global, deploy "all" to clean up the old guild registration.
A lightweight help command
listCommands() returns normal commands, subcommand roots, and context menus without duplicate alias entries:
const help = {
type: CommandType.LEGACY,
callback: ({ instance }) => {
const names = instance.listCommands()
.filter((item) => item.kind === "command")
.map((item) => item.name);
return `Try: ${names.join(", ")}`;
},
} satisfies CommandObject;For a polished help command, format each command's description and subcommand leaves. See Instance API for the returned metadata.