Fix embeds with images causing error when message cache size is set to 0
Created by: uwx
Summary
Sending an embed with an image attached causes an exception when the message cache size is set to 0. The exception comes from inside the SocketOnMessage handler, so it gets swallowed and does not affect client functionality. However, with a very large amount of guilds, this can be really annoying. This PR also fix a theoretical identical issue when the client receives a bulk message deletion, which with the message cache size set to 0 would call the event normally, but with an empty array instead of deleted message IDs.
Details
This happens because of the following line of code:
https://github.com/DSharpPlus/DSharpPlus/blob/f4338d65e26e2312f3c03801d53d758b43cfdfee/DSharpPlus/DiscordClient.cs#L1556
This will execute the contents of the else
block if the message cache is set to 0, which is already reserved case for when the TryGet
call succeeds. Because of the obtuse use of out
variables it's completely unnoticeable to a bystander that, when the message cache size is set to 0, the value of message
in the else
block is event_message
and not a message grabbed from the cache. The contents of the else
block look for properties that don't exist in event_message
(since they are only sent on message create, not message update) and everything crashes and burns.
Changes proposed
- Change two message cache size checks in DiscordClient to the correct form.
Notes
This took far too long. I was very tired when I wrote this. Things might not be very correct.