gaato/discord/bot does not have a README file
pub(all) suberror BotConfigError {
EmptyToken
InvalidShardConfig(message~ : String)
MismatchedSession(shard_id~ : Int)
InvalidEventBacklog(value~ : Int)
InvalidShutdownGrace(value~ : Int)
InvalidMaxMessageBytes(value~ : Int)
} derive(Debug)pub(all) suberror BotError {
FatallyClosed(code~ : Int)
AlreadyRunning
InvalidGatewayInfo(message~ : String)
SessionStartLimitExceeded(required~ : Int, remaining~ : Int, reset_after_ms~ : Int64)
ShardNotManaged(shard_id~ : Int)
GatewayRateLimited(opcode~ : Int, retry_after_ms~ : Int64)
GatewayRequestTimeout
} derive(Debug)pub struct Bot {
// private fields
}pub struct BotBuilder {
// private fields
}fn BotBuilder::BotBuilder(app : App, token~ : String, intents? : Intents, capabilities? : GatewayCapabilities, client? : Client, gateway_url? : String, shards? : ShardConfig, compress? : Bool, identify_queue? : &IdentifyQueue, sync? : CommandScope, sync_unowned? : UnownedCommands, resume? : Map[Int, BotSession], event_backlog? : Int, shutdown_grace_ms? : Int, max_message_bytes? : Int) -> BotBuilderfn BotBuilder::middleware(self : BotBuilder, middleware : async (GatewayCtx, Event, async (Event) -> Unit) -> Unit) -> Unitfn[T] BotBuilder::on(self : BotBuilder, event : EventType[T], handler : async (GatewayCtx, T) -> Unit) -> Unitfn BotBuilder::service(self : BotBuilder, name~ : String, handler : async (GatewayCtx) -> Unit) -> Unitpub struct EventType[T] {
// private fields
}pub struct Events {
}fn Events::application_command_permissions_update() -> EventType[GuildApplicationCommandPermissions]test "install a reaction role feature" {
fn install_reaction_role(
bot : @bot.BotBuilder,
role_id : @model.RoleId,
) -> Unit {
bot.on(@bot.Events::message_reaction_add(), (ctx, event) => {
guard event.guild_id is Some(guild_id) else { return }
guard event.emoji.name.to_option() == Some("✅") else { return }
if event.user_id == ctx.ready().user.id {
return
}
ctx
.app()
.http()
.add_member_role(
guild_id,
event.user_id,
role_id,
audit_reason="reaction role",
)
})
bot.on(@bot.Events::message_reaction_remove(), (ctx, event) => {
guard event.guild_id is Some(guild_id) else { return }
guard event.emoji.name.to_option() == Some("✅") else { return }
ctx
.app()
.http()
.remove_member_role(
guild_id,
event.user_id,
role_id,
audit_reason="reaction role removed",
)
})
}
ignore(install_reaction_role)
}pub(all) struct FetchedMembers {
members : Array[GuildMember]
presences : Array[PresenceUpdateEvent]
not_found : Array[Json]
} derive(Debug)pub struct GatewayCtx {
// private fields
}fn[T] GatewayCtx::expect_event(self : GatewayCtx, event_type : EventType[T], predicate : (T) -> Bool) -> PendingEvent[T]async fn GatewayCtx::fetch_guild_members(self : GatewayCtx, guild_id : Id[GuildMarker], select : MemberSelect, presences? : Bool, timeout_ms? : Int) -> FetchedMembersfn GatewayCtx::member_ref(self : GatewayCtx, guild_id : Id[GuildMarker], user_id : Id[UserMarker]) -> MemberRefasync fn GatewayCtx::request_guild_members(self : GatewayCtx, request : RequestGuildMembers) -> Unitasync fn GatewayCtx::request_soundboard_sounds(self : GatewayCtx, request : RequestSoundboardSounds) -> Unitasync fn GatewayCtx::resolve_channel(self : GatewayCtx, channel_id : Id[ChannelMarker]) -> Channel raise DiscordHttpErrorlet channel = ctx.resolve_channel(event.message.channel_id)
let is_thread = match channel.typ {
AnnouncementThread | PublicThread | PrivateThread => true
_ => false
}async fn[T] GatewayCtx::wait_for(self : GatewayCtx, event_type : EventType[T], predicate : (T) -> Bool, timeout_ms? : Int) -> T?async fn[A] GatewayCtx::wait_for_component(self : GatewayCtx, route : ComponentRoute[A], state : A, user? : Id[UserMarker], timeout_ms? : Int) -> ComponentCtx?pub struct PendingEvent[T] {
// private fields
}let DEFAULT_EVENT_BACKLOG : Intlet DEFAULT_SHUTDOWN_GRACE_MS : IntInstall
Download zipAn experimental Discord library for MoonBit: native/JS/Wasm REST, interactions, and gateway bots. Voice is in gaato/discord_voice.
Dependencies