You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/bot-api.md
+15-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# BotApi
2
2
3
-
`BotApi` is the stateless REST client used by a bot while handling events. After a gateway event arrives, handlers usually call it through the event session to send replies, recall channel messages, upload group/C2C files, manage announcements, schedules and pins, inspect reaction users, or create API permission requests.
3
+
`BotApi` is the shared typed REST client used by a bot while handling events. After a gateway event arrives, handlers usually call it through the event session to send replies, recall messages, upload group/C2C files, manage guild/channel resources, announcements, schedules, pins, reactions, permissions, roles, mute state, or audio controls.
4
4
5
5
When your bot is driven by `Client`, you normally do not construct `BotApi` yourself. Every event callback receives a session that exposes the shared API client:
6
6
@@ -26,15 +26,19 @@ let me = api.get_bot_info().await?;
26
26
| Area | Methods |
27
27
| --- | --- |
28
28
| Bot identity and gateway discovery |`get_bot_info`, `get_gateway`|
@@ -48,7 +52,9 @@ let params = GroupMessageParams::new_text("hello group");
48
52
group_session.send_message(params).await?;
49
53
```
50
54
51
-
Guild channel messages and DMs use `MessageParams` / `DirectMessageParams`. Group and C2C messages use `GroupMessageParams` / `C2CMessageParams`, matching QQ's open-message shape. For ark, embed, markdown, keyboard, or media payloads, set the corresponding field on the parameter struct.
55
+
Guild channel messages and DMs use `MessageParams` / `DirectMessageParams`. Group and C2C messages use `GroupMessageParams` / `C2CMessageParams`, matching QQ's open-message shape.
56
+
57
+
Inside event handlers, prefer the session helpers when they fit: `send_text_message`, `send_markdown_message`, `send_ark_message`, `send_embed_message`, `send_keyboard_message`, and group/C2C `send_media_message`. For lower-level API calls, use params constructors such as `new_markdown`, `new_ark`, `new_embed`, `new_keyboard`, and `new_media`; they fill the protocol message type for you.
`Client::new` returns `Result<Client<H>>` because it constructs the underlying `HttpClient`and may fail if TLS / DNS configuration is invalid.
13
+
`Client::new` returns `Result<Client<H>>` because it validates the token and constructs the underlying `HttpClient`.
14
14
15
15
## Constructors
16
16
@@ -21,14 +21,14 @@ client.start().await?;
21
21
22
22
## Lifecycle
23
23
24
-
-`start().await` — connects, identifies, and runs the event loop. Returns once the loop terminates (gracefully or via fatal error).
24
+
-`start().await` — performs startup REST calls, starts gateway sessions, and runs the event loop until the event channel closes.
25
25
Dropping the running `Client` task closes the gateway connection.
26
26
27
27
There are no `stop` / `is_connected` / `get_session_info` methods — the framework intentionally exposes a small surface and pushes session details into events instead. Use `EventHandler::ready` and `EventHandler::resumed` to observe lifecycle changes.
28
28
29
29
## Reconnect behaviour
30
30
31
-
`start()`reconnects automatically on transient gateway failures, applying the throttling described in the [gateway guide](../guide/gateway.md). When a fatal failure (invalid token, unrecoverable handshake) is detected, `start()` resolves with the propagated `BotError`.
31
+
`start()`propagates startup failures from token validation, `get_bot_info`, and `get_gateway`. After gateway sessions are spawned, transient gateway failures are retried with the throttling described in the [gateway guide](../guide/gateway.md); unrecoverable identify failures stop that shard's reconnect loop and are logged by the session manager.
Copy file name to clipboardExpand all lines: docs/api/models/messages.md
+17-9Lines changed: 17 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,14 +11,14 @@ Group and C2C messages have their own models:
11
11
-`GroupMessage` maps to `GROUP_AT_MESSAGE_CREATE`; the key routing field is `group_openid`.
12
12
-`C2CMessage` maps to `C2C_MESSAGE_CREATE`; the key routing field usually comes from `author.user_openid`.
13
13
14
-
These event models retain platform-provided message id, content, attachments, mentions, timestamp, references, and internal `event_id`. For plain replies, prefer `session.reply(...)` from the matching reply session. For richer replies, build the matching parameter struct manually.
14
+
These event models retain platform-provided message id, content, attachments, mentions, timestamp, references, and internal `event_id`. Message id, content, author, routing id, and timestamp are required fields on normal message events; group/C2C messages also carry the required open-message `message_type`. Optional protocol fields stay optional.
15
+
16
+
Attachments use `MessageAttachment`. When an attachment appears, the filename, content type, size, and URL are plain fields. `id` stays optional because open-message attachment payloads may omit it, while `width` and `height` default to `0` for non-image or payloads that do not include dimensions.
The rich constructors are `new_markdown`, `new_ark`, `new_embed`, `new_keyboard`, and, for group/C2C messages, `new_media`. Set fields directly only when you need a protocol field not covered by those constructors:
44
52
45
53
-`embed` for embed messages.
46
54
-`ark` for ark templates.
@@ -64,9 +72,9 @@ let params = DirectMessageParams::new_text("hello");
Group and C2C messages use the platform's numeric `msg_type`. Text generally keeps the default value 0; media uses 7; markdown, ark, embed, and other types follow the platform's protocol values. Guild channel messages use the Rust-modeled`MessageCreateType`.
77
+
Group and C2C messages still serialize to the platform's open-message type codes, but normal user code should use session helpers or params constructors instead of setting the numeric value by hand. Guild channel and direct-message params use`MessageCreateType` internally.
0 commit comments