Discord REST API client for Cloudflare-style bots written in MoonBit
Dependencies
///|
test {
let rest = new_rest_client(token="DISCORD_BOT_TOKEN")
let api = new_api(rest)
// Prepare and inspect request details before calling API
let prepared = rest.prepare_request(
request_method_get(),
route_channel_messages("1234567890"),
request_options(query=[("limit", "10")]),
)
inspect(
prepared.url,
content="https://discord.com/api/v10/channels/1234567890/messages?limit=10",
)
// API modules are available from new_api(rest)
inspect(api.users.rest.options.timeout_ms, content="15000")
}just check
just test
just infomoon build src/cfw --target js
npx wrangler dev --config fixtures/wrangler.jsoncpub struct API {
channels : ChannelsAPI
interactions : InteractionsAPI
webhooks : WebhooksAPI
users : UsersAPI
guilds : GuildsAPI
voice : VoiceAPI
}async fn ChannelsAPI::create_message(self : ChannelsAPI, channel_id : String, body : Json, auth_mode? : AuthMode) -> Result[Json, RestError]async fn ChannelsAPI::create_reaction(self : ChannelsAPI, channel_id : String, message_id : String, emoji : String) -> Result[Json, RestError]async fn ChannelsAPI::delete_message(self : ChannelsAPI, channel_id : String, message_id : String) -> Result[Json, RestError]async fn ChannelsAPI::delete_own_reaction(self : ChannelsAPI, channel_id : String, message_id : String, emoji : String) -> Result[Json, RestError]async fn ChannelsAPI::edit_message(self : ChannelsAPI, channel_id : String, message_id : String, body : Json, auth_mode? : AuthMode) -> Result[Json, RestError]async fn ChannelsAPI::get_message(self : ChannelsAPI, channel_id : String, message_id : String) -> Result[Json, RestError]async fn ChannelsAPI::get_messages(self : ChannelsAPI, channel_id : String, query? : Array[(String, String)]) -> Result[Json, RestError]async fn ChannelsAPI::trigger_typing_indicator(self : ChannelsAPI, channel_id : String) -> Result[Json, RestError]pub(all) struct FetchResponse {
ok : Bool
status : Int
content_type : String?
body : String
}async fn InteractionsAPI::delete_followup_message(self : InteractionsAPI, application_id : String, interaction_token : String, message_id : String) -> Result[Json, RestError]async fn InteractionsAPI::delete_reply(self : InteractionsAPI, application_id : String, interaction_token : String) -> Result[Json, RestError]async fn InteractionsAPI::edit_followup_message(self : InteractionsAPI, application_id : String, interaction_token : String, message_id : String, body : Json) -> Result[Json, RestError]async fn InteractionsAPI::edit_reply(self : InteractionsAPI, application_id : String, interaction_token : String, body : Json) -> Result[Json, RestError]async fn InteractionsAPI::follow_up(self : InteractionsAPI, application_id : String, interaction_token : String, body : Json) -> Result[Json, RestError]async fn InteractionsAPI::get_followup_message(self : InteractionsAPI, application_id : String, interaction_token : String, message_id : String) -> Result[Json, RestError]async fn InteractionsAPI::get_original_response(self : InteractionsAPI, application_id : String, interaction_token : String) -> Result[Json, RestError]async fn InteractionsAPI::reply(self : InteractionsAPI, interaction_id : String, interaction_token : String, body : Json, auth_mode? : AuthMode) -> Result[Json, RestError]pub(all) struct PreparedRequest {
meth : RequestMethod
url : String
headers : Map[String, String]
body : String?
}async fn RestClient::delete(self : RestClient, route : String, options? : RequestOptions) -> Result[Json, RestError]async fn RestClient::get(self : RestClient, route : String, options? : RequestOptions) -> Result[Json, RestError]async fn RestClient::patch(self : RestClient, route : String, options? : RequestOptions) -> Result[Json, RestError]async fn RestClient::post(self : RestClient, route : String, options? : RequestOptions) -> Result[Json, RestError]fn RestClient::prepare_request(self : RestClient, meth : RequestMethod, route : String, options : RequestOptions) -> PreparedRequestasync fn RestClient::put(self : RestClient, route : String, options? : RequestOptions) -> Result[Json, RestError]async fn RestClient::request(self : RestClient, meth : RequestMethod, route : String, options : RequestOptions) -> Result[Json, RestError]async fn WebhooksAPI::delete_message(self : WebhooksAPI, id : String, token : String, message_id : String, thread_id? : String) -> Result[Json, RestError]async fn WebhooksAPI::edit_message(self : WebhooksAPI, id : String, token : String, message_id : String, body : Json) -> Result[Json, RestError]async fn WebhooksAPI::execute(self : WebhooksAPI, id : String, token : String, body : Json, wait? : Bool, thread_id? : String) -> Result[Json, RestError]async fn WebhooksAPI::get_message(self : WebhooksAPI, id : String, token : String, message_id : String, thread_id? : String) -> Result[Json, RestError]fn request_options(auth_mode? : AuthMode, body? : Json, query? : Array[(String, String)], headers? : Map[String, String]) -> RequestOptionsfn route_channel_message(channel_id : String, message_id : String) -> Stringfn route_channel_message_own_reaction(channel_id : String, message_id : String, emoji : String) -> Stringfn route_guild_voice_state(guild_id : String, user_id : String) -> Stringfn route_interaction_callback(interaction_id : String, interaction_token : String) -> Stringfn route_webhook_message(id : String, token : String, message_id : String) -> StringDiscord REST API client for Cloudflare-style bots written in MoonBit
Dependencies