framework

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package framework provides a simple embedding API for running a single Discord bot with a JavaScript authoring runtime inside any Go application.

The main entrypoint is New(), which accepts functional options:

bot, err := framework.New(
    framework.WithCredentialsFromEnv(),
    framework.WithScript("./my-bot/index.js"),
    framework.WithSyncOnStart(true),
)
bot.Run(ctx)

For custom native modules, use WithRuntimeModuleRegistrars.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	// contains filtered or unexported fields
}

Bot is the public single-bot wrapper around the internal runtime.

func New

func New(opts ...Option) (*Bot, error)

New creates one explicit bot instance without any repository scanning.

func (*Bot) Close

func (b *Bot) Close() error

Close shuts down the bot runtime and Discord session.

func (*Bot) Open

func (b *Bot) Open() error

Open optionally syncs commands, then opens the Discord gateway session.

func (*Bot) Run

func (b *Bot) Run(ctx context.Context) error

Run opens the session and blocks until the context is canceled.

func (*Bot) SyncCommands

func (b *Bot) SyncCommands() error

SyncCommands manually syncs the bot's application commands.

type Config

type Config struct {
	Credentials             Credentials
	ScriptPath              string
	RuntimeConfig           map[string]any
	SyncOnStart             bool
	RuntimeModuleRegistrars []engine.RuntimeModuleRegistrar
}

Config describes the simple single-bot embedding path.

type Credentials

type Credentials struct {
	BotToken      string
	ApplicationID string
	GuildID       string
	PublicKey     string
	ClientID      string
	ClientSecret  string
}

Credentials holds the explicit Discord settings needed to run one bot.

type Option

type Option func(*Config) error

Option configures the public single-bot framework constructor.

func WithCredentials

func WithCredentials(credentials Credentials) Option

WithCredentials configures explicit Discord credentials.

func WithCredentialsFromEnv

func WithCredentialsFromEnv() Option

WithCredentialsFromEnv loads Discord credentials from the same env vars as the CLI.

func WithRuntimeConfig

func WithRuntimeConfig(runtimeConfig map[string]any) Option

WithRuntimeConfig injects arbitrary runtime config values into ctx.config.

func WithRuntimeModuleRegistrars

func WithRuntimeModuleRegistrars(registrars ...engine.RuntimeModuleRegistrar) Option

WithRuntimeModuleRegistrars appends custom per-runtime native module registrars.

func WithScript

func WithScript(path string) Option

WithScript configures the explicit JavaScript bot script path.

func WithSyncOnStart

func WithSyncOnStart(enabled bool) Option

WithSyncOnStart enables a command sync before opening the gateway session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL