disagreement/docs/caching.md
Slipstream 98afb89629
Some checks failed
Deploy MkDocs / deploy (push) Has been cancelled
Add Guild.me property (#90)
2025-06-15 18:13:06 -06:00

1.1 KiB

Caching

Disagreement ships with a simple in-memory cache used by the HTTP and Gateway clients. Cached objects reduce API requests and improve performance.

The client automatically caches guilds, channels and users as they are received from events or HTTP calls. You can access cached data through lookup helpers such as Client.get_guild.

Once you have a Guild object you can look up its cached members. Guild.get_member retrieves a member by ID, while Guild.get_member_named searches by username or nickname:

guild = client.get_guild(123456789012345678)
member = guild.get_member_named("Slipstream")
if member:
    print(member.display_name)

To access the bot's own member object, use the Guild.me property. It returns None if the bot is not in the guild or its user data hasn't been loaded:

bot_member = guild.me
if bot_member:
    print(bot_member.joined_at)

The cache can be cleared manually if needed:

client.cache.clear()

Next Steps