Hazel

API Reference

Complete API documentation for the Hazel Bot SDK

This reference documents all public APIs in the Hazel Bot SDK.

Entry Points

The SDK provides two ways to create a bot:

FunctionUse Case
runHazelBotSimplified setup with automatic config loading
createHazelBotFull control for advanced use cases

runHazelBot

The recommended way to create a bot. Handles configuration, signal handling, and lifecycle automatically.

import { Effect } from "effect"
import { runHazelBot } from "@hazel/bot-sdk"

runHazelBot({
	commands, // Optional: CommandGroup
	layers, // Optional: Additional Effect layers
	setup: (bot) =>
		Effect.gen(function* () {
			// Register handlers here
		}),
})

createHazelBot

For advanced use cases where you need full control over the runtime:

import { Effect } from "effect"
import { createHazelBot, HazelBotClient } from "@hazel/bot-sdk"

const runtime = createHazelBot({
	botToken: process.env.BOT_TOKEN!,
	commands,
})

const program = Effect.gen(function* () {
	const bot = yield* HazelBotClient
	// ...
	yield* bot.start
	yield* Effect.never
})

runtime.runPromise(program.pipe(Effect.scoped))

Reference Pages

Quick Reference

Event Handlers

MethodDescription
bot.onMessage(handler)New messages
bot.onMessageUpdate(handler)Message edits
bot.onMessageDelete(handler)Message deletions
bot.onChannelCreated(handler)New channels
bot.onChannelUpdated(handler)Channel updates
bot.onChannelDeleted(handler)Channel deletions
bot.onChannelMemberAdded(handler)Member joins
bot.onChannelMemberRemoved(handler)Member leaves
bot.onCommand(command, handler)Slash commands

Message Operations

MethodDescription
bot.message.send(channelId, content)Send a message
bot.message.reply(message, content)Reply to a message
bot.message.update(message, content)Edit a message
bot.message.delete(messageId)Delete a message
bot.message.react(message, emoji)React with emoji

Other Operations

MethodDescription
bot.typing.start(channelId, memberId)Show typing indicator
bot.typing.stop(typingIndicatorId)Hide typing indicator
bot.channel.update(channel, updates)Update channel
bot.withErrorHandler(ctx)Wrap handler with error handling
bot.startStart the bot
bot.getAuthContextGet bot auth context

On this page