A Pony library for working with Discord's API.
- API - v10
- Gateway - v10
- Voice - Unsupported!
- Requires ponyc 0.68.0 or later.
- Install corral
corral add github.com/vxern/discord.pony.git --version 1.0.0corral fetchto fetch your dependenciescorral run -- ponyc -Dopenssl_3.0.xto compile your application
discord.pony depends on ponylang/ssl. It requires a C SSL library to be installed. Please see the ssl installation instructions for more information.
An SSL version must be selected at compile time, or the build fails with You must select an SSL version to use. Pass -Dopenssl_3.0.x, -Dopenssl_4.0.x,
-Dopenssl_1.1.x or -Dlibressl to match the library you have installed.
The library is split across four packages, and Pony does not re-export across package boundaries, so pull in whichever ones you use:
use "discord"forBot, which pairs a REST client with a gateway connection, along with the CDN and message formatting helpersuse "discord/rest"forRest,RoutesandRestOptionsuse "discord/gateway"forGateway,EventsandGatewayOptionsuse "discord/data"for the Discord objects themselves, such asSnowflake,MessageandGatewayIntent
Note that constructing a Bot opens a gateway connection straight away. For
REST-only work, construct a Rest on its own.
Working examples live in examples/. Each one reads the bot token
from the DISCORD_TOKEN environment variable, so it never lands in the process
arguments, where any other user on the machine could read it:
corral run -- ponyc -Dopenssl_3.0.x -o build ./examples/polls
DISCORD_TOKEN=<bot-token> ./build/polls <channel-id>- β
Connection reuse, with a pool of up to 20 keep-alive connections
- β Requests held back when every connection is busy, and handed on as one comes free
- β
Timeouts
- β 15s on the connect and the TLS handshake
- β 30s on the response, so a connection that goes quiet cannot stall a bucket
- β
Rate limits
- β
Per-bucket windows, taken from
X-RateLimit-RemainingandX-RateLimit-Reset-After - β
Buckets keyed by Discord's own
X-RateLimit-Buckethash, scoped by major parameter - β Global 429 handling, pausing every bucket for as long as the response asks for
- β 50 requests a second, and the Cloudflare limit of 10,000 in 10 minutes
- β
Per-bucket windows, taken from
- β
Retries
- β 3 attempts on 500, 502, 503 and 504, and on a request that never comes back
- β Exponential backoff with jitter
- β Bounded queues, 1,000 to a bucket and 10,000 across the client
- β Idle buckets swept after 10 minutes, so a long-lived client holds no more than it uses
- β Audit log reasons, on every route that takes one
- β
File uploads, as
multipart/form-data
- Application Role Connection Metadata
- β Get Application Role Connection Metadata Records
- β Update Application Role Connection Metadata Records
- Application
- β Get Current Application
- β Edit Current Application
- β Get Application Activity Instance
- Audit Log
- β Get Guild Audit Log
- Auto Moderation
- β List Auto Moderation Rules for Guild
- β Get Auto Moderation Rule
- β Create Auto Moderation Rule
- β Modify Auto Moderation Rule
- β Delete Auto Moderation Rule
- Channel
- β Get Channel
- β Modify Channel
- β Delete/Close Channel
- β Set Voice Channel Status
- β Edit Channel Permissions
- β Delete Channel Permission
- β Get Channel Invites
- β Create Channel Invite
- β Follow Announcement Channel
- β Trigger Typing Indicator
- β Group DM Add Recipient
- β Group DM Remove Recipient
- β Start Thread from Message
- β Start Thread without Message
- β Start Thread in Forum or Media Channel
- β Join Thread
- β Add Thread Member
- β Leave Thread
- β Remove Thread Member
- β Get Thread Member
- β List Thread Members
- β List Public Archived Threads
- β List Private Archived Threads
- β List Joined Private Archived Threads
- Emoji
- β List Guild Emojis
- β Get Guild Emoji
- β Create Guild Emoji
- β Modify Guild Emoji
- β Delete Guild Emoji
- β List Application Emojis
- β Get Application Emoji
- β Create Application Emoji
- β Modify Application Emoji
- β Delete Application Emoji
- Entitlement
- β List Entitlements
- β Get Entitlement
- β Consume an Entitlement
- β Create Test Entitlement
- β Delete Test Entitlement
- Guild
- β Get Guild
- β Get Guild Preview
- β Modify Guild
- β Get Guild Channels
- β Create Guild Channel
- β Modify Guild Channel Positions
- β List Active Guild Threads
- β Get Guild Member
- β List Guild Members
- β Search Guild Members
- β Add Guild Member
- β Modify Guild Member
- β Modify Current Member
- β Modify Current User Nick (deprecated)
- β Add Guild Member Role
- β Remove Guild Member Role
- β Remove Guild Member
- β Get Guild Bans
- β Get Guild Ban
- β Create Guild Ban
- β Remove Guild Ban
- β Bulk Guild Ban
- β Get Guild Roles
- β Get Guild Role
- β Get Guild Role Member Counts
- β Create Guild Role
- β Modify Guild Role Positions
- β Modify Guild Role
- β Delete Guild Role
- β Get Guild Prune Count
- β Begin Guild Prune
- β Get Guild Voice Regions
- β Get Guild Invites
- β Get Guild Integrations
- β Delete Guild Integration
- β Get Guild Widget Settings
- β Modify Guild Widget
- β Get Guild Widget
- β Get Guild Vanity URL
- β Get Guild Widget Image
- β Get Guild Welcome Screen
- β Modify Guild Welcome Screen
- β Get Guild Onboarding
- β Modify Guild Onboarding
- β Modify Guild Incident Actions
- Guild Scheduled Event
- β List Scheduled Events for Guild
- β Create Guild Scheduled Event
- β Get Guild Scheduled Event
- β Modify Guild Scheduled Event
- β Delete Guild Scheduled Event
- β Get Guild Scheduled Event Users
- Guild Template
- β Get Guild Template
- β Get Guild Templates
- β Create Guild Template
- β Sync Guild Template
- β Modify Guild Template
- β Delete Guild Template
- Invite
- β Get Invite
- β Delete Invite
- β Get Target Users
- β Update Target Users
- β Get Target Users Job Status
- Lobby
- β Create Lobby
- β Create or Join Lobby
- β Get Lobby
- β Modify Lobby
- β Delete Lobby
- β Add a Member to a Lobby
- β Bulk Update Lobby Members
- β Remove a Member from a Lobby
- β Leave Lobby
- β Link Channel to Lobby
- β Unlink Channel from Lobby
- β Send Lobby Message
- β Get Lobby Messages
- β Update Lobby Message Moderation Metadata
- β Create Lobby Channel Invite for Self
- β Create Lobby Channel Invite for User
- Message
- β Get Channel Messages
- β Search Guild Messages
- β Get Channel Message
- β Create Message
- β Crosspost Message
- β Create Reaction
- β Delete Own Reaction
- β Delete User Reaction
- β Get Reactions
- β Delete All Reactions
- β Delete All Reactions for Emoji
- β Edit Message
- β Delete Message
- β Bulk Delete Messages
- β Get Channel Pins
- β Pin Message
- β Unpin Message
- β Get Pinned Messages (deprecated)
- β Pin Message (deprecated)
- β Unpin Message (deprecated)
- Poll
- β Get Answer Voters
- β End Poll
- SKU & Subscription
- β List SKUs
- β List SKU Subscriptions
- β Get SKU Subscription
- Soundboard
- β Send Soundboard Sound
- β List Default Soundboard Sounds
- β List Guild Soundboard Sounds
- β Get Guild Soundboard Sound
- β Create Guild Soundboard Sound
- β Modify Guild Soundboard Sound
- β Delete Guild Soundboard Sound
- Stage Instance
- β Create Stage Instance
- β Get Stage Instance
- β Modify Stage Instance
- β Delete Stage Instance
- Sticker
- β Get Sticker
- β List Sticker Packs
- β Get Sticker Pack
- β List Guild Stickers
- β Get Guild Sticker
- β Create Guild Sticker
- β Modify Guild Sticker
- β Delete Guild Sticker
- User
- β Get Current User
- β Get User
- β Modify Current User
- β Get Current User Guilds
- β Get Current User Guild Member
- β Leave Guild
- β Create DM
- β Create Group DM
- β Get Current User Connections
- β Get Current User Application Role Connection
- β Update Current User Application Role Connection
- β Delete Current User Application Role Connection
- Voice
- β List Voice Regions
- β Get Current User Voice State
- β Get User Voice State
- β Modify Current User Voice State
- β Modify User Voice State
- Webhook
- β Create Webhook
- β Get Channel Webhooks
- β Get Guild Webhooks
- β Get Webhook
- β Get Webhook with Token
- β Modify Webhook
- β Modify Webhook with Token
- β Delete Webhook
- β Delete Webhook with Token
- β Execute Webhook
- β Execute Slack-Compatible Webhook
- β Execute GitHub-Compatible Webhook
- β Get Webhook Message
- β Edit Webhook Message
- β Delete Webhook Message
- Receiving and Responding
- β Create Interaction Response
- β Get Original Interaction Response
- β Edit Original Interaction Response
- β Delete Original Interaction Response
- β Create Followup Message
- β Get Followup Message
- β Edit Followup Message
- β Delete Followup Message
- Application Commands
- β Get Global Application Commands
- β Create Global Application Command
- β Get Global Application Command
- β Edit Global Application Command
- β Delete Global Application Command
- β Bulk Overwrite Global Application Commands
- β Get Guild Application Commands
- β Create Guild Application Command
- β Get Guild Application Command
- β Edit Guild Application Command
- β Delete Guild Application Command
- β Bulk Overwrite Guild Application Commands
- β Get Guild Application Command Permissions
- β Get Application Command Permissions
- β Edit Application Command Permissions
- β Batch Edit Application Command Permissions
- OAuth2
- β Get Current Bot Application Information
- β Get Current Authorization Information
- Gateway
- β Get Gateway
- β Get Gateway Bot
- β Identify
- β Resume
- β
Heartbeat
- β Jittered first beat
- β Acknowledgement tracking, with a reconnect when a beat goes unacknowledged
- β Out-of-band beats on request (opcode 1)
- β
Automatic reconnect
- β Exponential backoff with jitter, reset once the session settles
- β Close code handling, staying down on the codes that cannot be recovered from
- β Session invalidation handling (opcode 9), resuming or re-identifying as instructed
- β Stage timeouts, so a connect, hello, ready or close that never arrives cannot hang the gateway
- β
Send rate limits
- β 120 commands per 60s, with slots held back for heartbeats
- β 5 presence updates per 20s
- β
Identify concurrency, taken from
max_concurrency
- β 4096-byte payload limit, enforced before the wire
- β 4 MiB receive limit, and a nesting depth limit checked before a frame is parsed
- β Bounded send queue, retained across reconnects
- β Backpressure
- β Session start limit, checked before identifying
- β
Sharding
- β
Automatic shard count, taken from
Get Gateway Bot - β Explicit shard count, and running only a subset so the rest can live in other processes
- β
Identify concurrency shared across shards, bucketed by
shard_id % max_concurrency - β Guild events routed to the shard that owns the guild
- β
Automatic shard count, taken from
- β Transport compression (
zlib-stream,zstd-stream) - β Payload compression
- β ETF encoding
- β Presence Update
- β Voice State Update
- β Request Guild Members
- β Request Soundboard Sounds
- β Request Channel Info
- Lifecycle
- β Ready
- β Resumed
- β Rate Limited
- Application Commands
- β Application Command Permissions Update
- Auto Moderation
- β Auto Moderation Rule Create
- β Auto Moderation Rule Update
- β Auto Moderation Rule Delete
- β Auto Moderation Action Execution
- Channel
- β Channel Create
- β Channel Update
- β Channel Delete
- β Channel Info
- β Channel Pins Update
- Thread
- β Thread Create
- β Thread Update
- β Thread Delete
- β Thread List Sync
- β Thread Member Update
- β Thread Members Update
- Entitlement
- β Entitlement Create
- β Entitlement Update
- β Entitlement Delete
- Guild
- β Guild Create
- β Guild Update
- β Guild Delete
- β Guild Audit Log Entry Create
- β Guild Ban Add
- β Guild Ban Remove
- β Guild Emojis Update
- β Guild Stickers Update
- β Guild Integrations Update
- β Guild Member Add
- β Guild Member Remove
- β Guild Member Update
- β Guild Members Chunk
- β Guild Role Create
- β Guild Role Update
- β Guild Role Delete
- Guild Scheduled Event
- β Guild Scheduled Event Create
- β Guild Scheduled Event Update
- β Guild Scheduled Event Delete
- β Guild Scheduled Event User Add
- β Guild Scheduled Event User Remove
- Soundboard
- β Guild Soundboard Sound Create
- β Guild Soundboard Sound Update
- β Guild Soundboard Sound Delete
- β Guild Soundboard Sounds Update
- β Soundboard Sounds
- Integration
- β Integration Create
- β Integration Update
- β Integration Delete
- Interaction
- β Interaction Create
- Invite
- β Invite Create
- β Invite Delete
- Message
- β Message Create
- β Message Update
- β Message Delete
- β Message Delete Bulk
- β Message Reaction Add
- β Message Reaction Remove
- β Message Reaction Remove All
- β Message Reaction Remove Emoji
- Poll
- β Message Poll Vote Add
- β Message Poll Vote Remove
- Presence
- β Presence Update
- β Typing Start
- β User Update
- Stage Instance
- β Stage Instance Create
- β Stage Instance Update
- β Stage Instance Delete
- Subscription
- β Subscription Create
- β Subscription Update
- β Subscription Delete
- Voice
- β Voice Channel Effect Send
- β Voice Channel Status Update
- β Voice Channel Start Time Update
- β Voice State Update
- β Voice Server Update
- Webhook
- β Webhooks Update
- Application
- β Application
- β ApplicationIntegrationTypeConfiguration
- β InstallParams
- β ActivityInstance
- β ActivityLocation
- Application Command
- β ApplicationCommandOptionChoice
- β ApplicationCommandOption
- β ApplicationCommandPermission
- Application Role Connection Metadata
- β ApplicationRoleConnectionMetadata
- Audit Log
- β AuditLog
- β AuditLogEntry
- β OptionalAuditEntryInfo
- β AuditLogChange
- Auto Moderation
- β AutoModerationRule
- β AutoModerationTriggerMetadata
- β AutoModerationAction
- β AutoModerationActionMetadata
- Channel
- β Channel
- β FollowedChannel
- β PermissionOverwrite
- β ThreadMetadata
- β ThreadMember
- β DefaultReaction
- β ForumTag
- Component
- β ActionRowComponent
- β ButtonComponent
- β StringSelectComponent
- β SelectOption
- β TextInputComponent
- β UserSelectComponent
- β RoleSelectComponent
- β MentionableSelectComponent
- β ChannelSelectComponent
- β SelectDefaultValue
- β SectionComponent
- β TextDisplayComponent
- β ThumbnailComponent
- β MediaGalleryComponent
- β MediaGalleryItem
- β FileComponent
- β SeparatorComponent
- β ContainerComponent
- β LabelComponent
- β FileUploadComponent
- β RadioGroupComponent
- β RadioGroupOption
- β CheckboxGroupComponent
- β CheckboxGroupOption
- β CheckboxComponent
- β UnfurledMediaItem
- Emoji
- β Emoji
- Entitlement
- β Entitlement
- Guild
- β Guild
- β GuildPreview
- β GuildWidgetSettings
- β GuildWidget
- β GuildMember
- β Integration
- β IntegrationAccount
- β IntegrationApplication
- β Ban
- β WelcomeScreen
- β WelcomeScreenChannel
- β GuildOnboarding
- β OnboardingPrompt
- β OnboardingPromptOption
- β IncidentsData
- β GuildChannelPosition
- β GuildRolePosition
- Guild Scheduled Event
- β GuildScheduledEvent
- β GuildScheduledEventEntityMetadata
- β GuildScheduledEventRecurrenceRule
- β GuildScheduledEventRecurrenceRuleNWeekday
- β GuildScheduledEventUser
- Guild Template
- β GuildTemplate
- Interaction
- β Interaction
- β ApplicationCommand
- β ApplicationCommandData
- β ApplicationCommandInteractionDataOption
- β MessageComponentData
- β ModalSubmitData
- β ResolvedData
- β InteractionResponse
- β InteractionCallbackResponse
- β InteractionCallback
- β InteractionCallbackResource
- β InteractionCallbackActivityInstanceResource
- β GuildApplicationCommandPermissions
- Invite
- β Invite
- β InviteMetadata
- β InviteStageInstance
- Lobby
- β Lobby
- β LobbyMember
- β LobbyMessage
- Message
- β Message
- β MessageActivity
- β ApplicationCommandInteractionMetadata
- β MessageComponentInteractionMetadata
- β ModalSubmitInteractionMetadata
- β MessageInteraction
- β MessageCall
- β MessageReference
- β MessageSnapshot
- β MessageReaction
- β MessageReactionCountDetails
- β MessageEmbed
- β MessageEmbedVideo
- β MessageEmbedImage
- β MessageEmbedProvider
- β MessageEmbedAuthor
- β MessageEmbedFooter
- β MessageEmbedField
- β MessageAttachment
- β ChannelMention
- β AllowedMentions
- β RoleSubscriptionData
- β MessagePin
- β SharedClientTheme
- Permission
- β Role
- β RoleTags
- β RoleColors
- Poll
- β Poll
- β PollMedia
- β PollAnswer
- β PollResults
- β PollAnswerCount
- Sku
- β SKU
- Snowflake
- β Snowflake
- Soundboard
- β SoundboardSound
- Stage Instance
- β StageInstance
- Sticker
- β Sticker
- β StickerItem
- β StickerPack
- Subscription
- β Subscription
- Team
- β Team
- β TeamMember
- User
- β User
- β AvatarDecorationData
- β Collectibles
- β Nameplate
- β UserPrimaryGuild
- β Connection
- β ApplicationRoleConnection
- Webhook
- β Webhook