Skip to main content
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

1

Define Commands

Use prefix() and slash() to define commands with handlers.
2

Register Bot

Call createBot() once to register your commands and set the prefix.
3

Handle Events

Use on() to listen for Discord events like messageCreate or ready.
4

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:
prefix
function
Define prefix commands triggered by messages starting with your bot’s prefix.
slash
function
Define slash commands registered with Discord.
createBot
function
Register commands and configure your bot. Call this once per script.
on
function
Register event handlers for Discord events.
embed
function
Create rich embeds with builder methods.
kv
object
Access the key-value storage API.
cron
function
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

Embeds

Create rich embeds

Components

Add buttons and menus

Build docs developers (and LLMs) love