An experimental Discord library for MoonBit: native/JS/Wasm REST, interactions, and gateway bots. Voice is in gaato/discord_voice.
moon add gaato/discord///|
struct QuickstartEchoArgs {
text : String
times : Int32
}
///|
async fn run_echo_bot(token : String, scope : @discord.CommandScope) -> Unit {
let args : @discord.Args[QuickstartEchoArgs] = @discord.Args::map2(
@discord.arg_string(name="text", description="What to echo"),
@discord.arg_int32(
name="times",
description="How many times (1-5)",
min=1,
max=5,
).with_default(1),
(text, times) => { text, times, },
)
let echo = @discord.slash(
name="echo",
description="Echo your text back",
args~,
handler=Immediate((_ctx, value) => {
@discord.CommandReply::message(
content=Array::make(value.times, value.text).join("\n"),
)
}),
)
let app = @discord.AppBuilder()
app.command(echo)
let bot = @discord.BotBuilder(app.build(), token~, sync=scope)
bot.on(@discord.Events::ready(), (_ctx, ready) => {
println("ready as \{ready.user.username}")
})
bot.build().run()
}
///|
test "the quickstart bot compiles" {
ignore(run_echo_bot)
}| Application | Packages under gaato/discord |
|---|---|
| Gateway bot with commands and events | The root facade: AppBuilder, BotBuilder, typed Events. |
| REST-only tool or background job | http (routes, pagination, uploads, rate limiting), which brings model. |
| Serverless HTTP interactions (Cloudflare Workers, Deno, Bun, Node.js) | app and verify. |
| Native or moonrun Wasm HTTP interactions server | endpoint_http. |
| Tests without Discord | testkit for fixtures. http.Client::offline answers REST calls from your function. |
| Package | What it is | Native | JS | Wasm¹ |
|---|---|---|---|---|
| gaato/discord | Facade: the names a typical application uses directly | Yes | Yes² | Yes² |
| gaato/discord/model | Pure data: API entities and gateway payloads, no I/O | Yes | Yes | Yes |
| gaato/discord/http | REST Client, routes, rate limiting, multipart uploads | Yes | Yes | Yes |
| gaato/discord/gateway | Shard: connection state machine, heartbeat, resume | Yes | Yes | Yes |
| gaato/discord/interaction | Command and component builders, typed args, autocomplete data | Yes | Yes | Yes |
| gaato/discord/framework | Interaction routing, response gates, low-level response contexts | Yes | Yes | Yes |
| gaato/discord/app | Gateway-free typed commands, components and modals, HTTP endpoint, sync and policy | Yes | Yes | Yes |
| gaato/discord/bot | Gateway executor and typed gateway event descriptors | Yes | Yes | Yes |
| gaato/discord/endpoint_http | Signed-interactions HTTP server (serve_interactions) | Yes | No | Yes |
| gaato/discord/cache | Opt-in, gateway-driven in-memory cache | Yes | Yes | Yes |
| gaato/discord/util | Permissions, mentions, timestamps, CDN URLs | Yes | Yes | Yes |
| gaato/discord/verify | Pure MoonBit Ed25519 request verification | Yes | Yes | Yes |
| gaato/discord/ratelimit | In-memory Discord rate limiter | Yes | Yes | Yes |
| gaato/discord/cooldown | Command cooldown store and in-memory fixed windows | Yes | Yes | Yes |
| gaato/discord/queue | Identify queue and in-memory implementation | Yes | Yes | Yes |
| gaato/discord/coordinator | Experimental TCP coordinator for multi-process Identify, REST limits and cooldowns | Yes | No | Yes |
| gaato/discord/telemetry | Structured REST, gateway and dispatch observability values | Yes | Yes | Yes |
| gaato/discord/testkit | Deterministic interaction and model fixtures | Yes | Yes | Yes |
Install
Download zipAn experimental Discord library for MoonBit: native/JS/Wasm REST, interactions, and gateway bots. Voice is in gaato/discord_voice.