Skip to main content

Overview

The createBot() function is the main entry point for initializing your Flora bot. It registers prefix commands, slash commands, and sets up event handlers.

Signature

function createBot(options: CreateOptions): void

Parameters

options
CreateOptions
required
Configuration object for the bot

Return Value

Returns void. The function sets up global event handlers and registers commands.

Behavior

  • Idempotent: Can be called multiple times but only initializes once
  • Auto-registration: Slash commands are automatically registered with Discord
  • Event handling: Sets up messageCreate and interactionCreate handlers
  • Prefix parsing: Automatically parses prefix commands from messages

Example

const pingCmd = prefix({
  name: 'ping',
  description: 'Replies with pong',
  run: async (ctx) => {
    await ctx.reply('Pong!')
  }
})

const greetSlash = slash({
  name: 'greet',
  description: 'Greet someone',
  options: [{
    name: 'user',
    description: 'User to greet',
    type: 'string',
    required: true
  }],
  run: async (ctx) => {
    const user = ctx.options.user
    await ctx.reply(`Hello, ${user}!`)
  }
})

createBot({
  prefix: '!',
  commands: [pingCmd],
  slashCommands: [greetSlash]
})

Notes

  • Must be called before the bot starts processing events
  • Prefix and slash commands can be used together
  • The commands and prefixCommands parameters are equivalent
  • Slash commands are automatically registered to the guild on bot startup

Build docs developers (and LLMs) love