DisCatSharp Analyzer Rule DCS1103
This rule flags any access to DiscordClient.Presences, which has been removed.
| Property | Value |
|---|---|
| ID | DCS1103 |
| Severity | Error |
| Category | Usage |
| Supersedes | DCS1101 |
Why this property was removed
DiscordClient.Presences returned a flat IReadOnlyDictionary<ulong, DiscordPresence> that picked one arbitrary guild presence per user. This was:
- Ambiguous — users in multiple guilds had a single presence returned from an unspecified guild
- Expensive — building the flat view required iterating the entire presence store each access
- Misleading — Discord presences are fundamentally guild-scoped; a flat view hides that reality
Other major Discord libraries (discord.js, discord.py, JDA) expose presences only at the guild level.
Replacement APIs
| Old usage | Replacement |
|---|---|
client.Presences[userId] |
client.GetPresences(userId) — returns IReadOnlyDictionary<ulong guildId, DiscordPresence> |
client.Presences.Values.Where(p => p.UserId == id) |
client.GetPresences(id).Values |
client.Presences.ContainsKey(userId) |
client.GetPresences(userId).Count > 0 |
| Checking bot's own presence | client.CurrentPresence |
| Guild-scoped presence | guild.Presences or member.Presence |
What the code fix handles
The code fix handles two patterns:
Indexer access
// Before
var presence = client.Presences[userId];
// After (auto-fixed)
var presence = client.GetPresences(userId);
Bare property access
// Before
var all = client.Presences;
// After (auto-fixed with placeholder)
var all = client.GetPresences(/* TODO: pass the target user ID */ userId);
For the bare access case, the code fix inserts a userId placeholder with a TODO comment since the replacement requires a user ID argument that the original code did not have.
Related APIs
DiscordClient.GetPresences(ulong userId)— user-specific presence lookup keyed by guild IDDiscordClient.CurrentPresence— the bot's own presence (tracked locally since bots never receive PRESENCE_UPDATE for themselves)DiscordGuild.Presences— guild-scoped presence cacheDiscordMember.Presence— guild-scoped member presence (returnsCurrentPresencefor the bot user)