The Flora SDK lets you build Discord bots using TypeScript that run inside the Flora runtime. Functions are available globally—no imports needed.
Installation
Install the SDK to get type definitions and build tools:
npm install @flora/sdk
# or
pnpm add @flora/sdk
Quickstart
Create a main.ts file with a simple prefix command:
const ping = prefix({
name: 'ping',
description: 'Respond with pong',
run: async (ctx) => {
const extra = ctx.args.join(' ') || 'none'
await ctx.reply(`pong! args: ${extra}`)
}
})
createBot({
prefix: '!',
commands: [ping]
})
Core Concepts
Define Commands
Use prefix() and slash() to define commands with handlers.
Register Bot
Call createBot() once to register your commands and set the prefix.
Handle Events
Use on() to listen for Discord events like messageCreate or ready.
Deploy
Deploy your script to Flora, where it runs in a sandboxed Deno runtime.
Global Functions
All SDK functions are available globally in the Flora runtime:
Define prefix commands triggered by messages starting with your bot’s prefix.
Define slash commands registered with Discord.
Register commands and configure your bot. Call this once per script.
Register event handlers for Discord events.
Create rich embeds with builder methods.
Access the key-value storage API.
Schedule recurring tasks with cron expressions.
Context Object
Every command and event handler receives a context object:
type Context = {
msg: EventPayload // The Discord event data
reply: (content) => Promise<void> // Send a reply
edit: (content) => Promise<void> // Edit the message/response
}
Reply Options
await ctx.reply('Hello, world!')
Command Arguments
Prefix Commands
Access arguments via ctx.args array:
const greet = prefix({
name: 'greet',
description: 'Greet someone',
run: async (ctx) => {
const name = ctx.args[0] || 'world'
await ctx.reply(`Hello, ${name}!`)
}
})
Slash Commands
Access typed options via ctx.options:
const echo = slash({
name: 'echo',
description: 'Echo your input',
options: [
{ name: 'text', description: 'Text to echo', type: 'string', required: true }
],
run: async (ctx) => {
const text = ctx.options.text as string
await ctx.reply({ content: text, ephemeral: true })
}
})
Type Safety
The SDK exports TypeScript types for all APIs:
import type {
MessageContext,
InteractionContext,
SlashCommand,
Command
} from '@flora/sdk'
Types are generated from the Rust runtime and kept in sync automatically.
Next Steps
Commands
Learn about prefix and slash commands
Events
Handle Discord events
Components
Add buttons and menus