question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DiscordMember lacks of user properties when the cache is empty on Guild Member Removed event

See original GitHub issue

Summary

The DiscordMember entity doesn’t use the DiscordUser’s properties, instead it searches this in the user cache.

Details

I found that the DiscordMember entity doesn’t have the username, discriminator, avatar, basically all the general fields from the DiscordUser entity when this is not in the cache. I was searching the cause of this and I found that DiscordMember searches the user in the user cache then it uses its properties. I found this problem in the Guild Member Removed event when I started my bot with the cache empty. I believe Discord sends the full data of the user that left the server.

Steps to reproduce

  1. Start the bot with the cache empty (i.e. have only the member intent enabled or not)
  2. Try to access member’s username in the guild member removed event
  3. You will get a KeyNotFoundException

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
FenikkusuKonekocommented, Dec 25, 2020

I have only the member intent enabled. I found this in my bot dev and also in the logs of my public bot. I have the logs for it. I restarted my bot 2 days ago and this is one of the logs while trying to get the username of a member that left a guild and it wasn’t in the cache because the bot just started. The bot was supposed to send a leaving message. Maybe in your case the member was updated and added in the member cache, I don’t know.

2020-12-24 17:56:20.612 +01:00 [ERR] System.Collections.Generic.KeyNotFoundException: The given key '513749051393441794' was not present in the dictionary.
   at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNotFoundException(TKey key)
   at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)
   at DSharpPlus.Entities.DiscordMember.get_Username()
0reactions
Neuheitcommented, Feb 1, 2021

Okay sorry for the long wait, I tested this and was able to reproduce. I will get this issue fixed soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

None of my discord.js guildmember events are emitting ...
GUILD_PRESENCES. member and user caches are empty (or very close to it) on startup; Guild.memberCount returns count as of ready · GUILD_MEMBERS.
Read more >
The guildMemberRemove event is not thrown when there ...
When a member enters the guild, the GUILD_MEMBER_ADD event occurs, caches the member and passes the event to the client.
Read more >
Error when trying to read `message.guild.roles.cache`
I have no clue why the cache property is undefined in some cases and is defined in others. How would I find a...
Read more >
Interactions API Reference - discord.py
Represents a Discord interaction. An interaction happens when a user does an action that needs to be notified. Current examples are slash commands...
Read more >
Adding role gives an error: Cannot read property 'guild' of null
Hello, I'm trying to run this piece of code for my new bot. This is supposed to be a "muting" command, but it's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found