Skip to content

Commit 0f66593

Browse files
markmandelmazylol
authored andcommitted
Social SDK: Getting Lobby Chat History (discord#7659)
Adds a section to the Managing Lobbies documentation covering how to use `Client::GetLobbyMessagesWithLimit` to get a lobby's chat history.
1 parent ef5bcbc commit 0f66593

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

docs/discord-social-sdk/development-guides/managing-lobbies.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,46 @@ client->SetMessageCreatedCallback([&client](uint64_t messageId) {
151151
});
152152
```
153153

154+
---
155+
## Getting Lobby Chat History
156+
157+
You can retrieve previous messages from a lobby using the [`Client::GetLobbyMessagesWithLimit`] function. This allows you to fetch chat history for display when users join a lobby or need to see previous conversations.
158+
159+
The function takes a lobby ID and a limit parameter to specify how many recent messages to retrieve.
160+
161+
**Important limitations:**
162+
- Only a maximum of 200 messages and up to 72 hours of history can be retrieved
163+
- Only messages from lobbies the user is currently a member of can be retrieved
164+
165+
```cpp
166+
const uint64_t lobbyId = 01234567890;
167+
const uint32_t messageLimit = 50; // Number of recent messages to retrieve (max 200)
168+
169+
client->GetLobbyMessagesWithLimit(
170+
lobbyId, messageLimit,
171+
[](const discordpp::ClientResult &result, const std::vector<discordpp::MessageHandle> &messages) {
172+
if (result.Successful()) {
173+
std::cout << "? Retrieved " << messages.size()
174+
<< " messages from lobby chat history!\n";
175+
176+
// Process the messages (they are returned in chronological order)
177+
for (const auto &message : messages) {
178+
std::cout << "Message: " << message.Content() << std::endl;
179+
}
180+
} else {
181+
std::cerr << "? Failed to retrieve lobby chat history\n";
182+
}
183+
});
184+
```
185+
186+
The messages are returned as a list of [`MessageHandle`] objects, ordered chronologically from oldest to newest.
187+
Each [`MessageHandle`] contains the message content, author information, and timestamp.
188+
189+
This is particularly useful for:
190+
- Displaying recent chat when a user joins a lobby
191+
- Implementing chat history scrollback features
192+
- Preserving conversation context across game sessions
193+
154194
---
155195

156196
## Linking a Channel to Lobby
@@ -206,6 +246,7 @@ With your game able to create and manage lobbies, you can now implement addition
206246
[`ChannelHandle`]: https://discord.com/developers/docs/social-sdk/classdiscordpp_1_1ChannelHandle.html#ac32096b2ef15c5c220e9b7b92253cc46
207247
[`Client::CreateOrJoinLobby`]: https://discord.com/developers/docs/social-sdk/classdiscordpp_1_1Client.html#a8b4e195555ecaa89ccdfc0acd28d3512
208248
[`Client::CreateOrJoinLobbyWithMetadata`]: https://discord.com/developers/docs/social-sdk/classdiscordpp_1_1Client.html#a5c84fa76c73cf3c0bfd68794ca5595c1
249+
[`Client::GetLobbyMessagesWithLimit`]: https://discord.com/developers/docs/social-sdk/classdiscordpp_1_1Client.html#a0586192e85caf548b8b321f1cb21301f
209250
[`Client::LeaveLobby`]: https://discord.com/developers/docs/social-sdk/classdiscordpp_1_1Client.html#a8c78f797240b35d721383461a2e62926
210251
[`Client::SendLobbyMessage`]: https://discord.com/developers/docs/social-sdk/classdiscordpp_1_1Client.html#a779e0483f51dc99f0db3dd761d22ab6f
211252
[`Client::SetMessageCreatedCallback`]: https://discord.com/developers/docs/social-sdk/classdiscordpp_1_1Client.html#a28325a8e8c688a84ac851da4bc86e148

0 commit comments

Comments
 (0)