Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MessageUpdated sometimes returns a null SocketMessage if MessageCacheSize == 0 #1208

Closed
jmazouri opened this issue Dec 2, 2018 · 4 comments

Comments

@jmazouri
Copy link
Contributor

jmazouri commented Dec 2, 2018

I was seeing an issue where MessageUpdated was occasionally giving me a null arg2 (the SocketMessage), and was able to reproduce it (on the latest version) by sending a message with a URL for which Discord generates an embed automatically - such as https://github.com/RogueException/Discord.Net - but, notably, only when MessageCacheSize is 0; MessageUpdated's arg2 will never be null if the cache is enabled.

This seems to due to the fact that the MESSAGE_UPDATE gateway event, if updating a message to add an embed, doesn't contain author data - and the check on DiscordSocketClient.cs#1221 will only create a "detached" SocketMessage if the author is present. The SocketMessage passed to the event on DiscordSocketClient.cs#1212, after, remains null - as without MessageCacheSize being set, the call to channel.GetCachedMessage will always return null.

According to the documentation (and messages on DAPI), the presence of MessageCacheSize should only affect arg1 of MessageUpdated, but it seems that it indirectly affects both. I'm not sure what the best solution is in this case, but perhaps the "MESSAGE_UPDATE" case could be modified to return a SocketMessage with missing properties (or a less derived type that matches better). This would at least match the functionality described in Discord's API docs:

Unlike creates, message updates may contain only a subset of the full message object payload (but will always contain an id and channel_id).
https://discordapp.com/developers/docs/topics/gateway#message-update

Of course, the solution for now is just "Set MessageCacheSize", but I still think the event should return, at minimum, what the Discord API does (message and channel IDs).

@Joe4evr
Copy link
Contributor

Joe4evr commented Dec 2, 2018

The Cacheable always has the message ID. Channels are always cached, so that's never null and you can get the ID off that.

@jmazouri
Copy link
Contributor Author

jmazouri commented Dec 2, 2018

Good point, I'll have to implement a check for that - but I still think it should be made clearer, as the docs and event args imply the SocketMessage will never be null.

@Joe4evr
Copy link
Contributor

Joe4evr commented Dec 2, 2018

That has never been the behavior of Cacheable. And the doc also clearly says:

  1. "[...] if it could be pulled from cache."
  2. "[...] in cases where the entity cannot be pulled from cache, it is null."

@jmazouri
Copy link
Contributor Author

jmazouri commented Dec 2, 2018

The Cacheable is not the issue - it makes sense that the original message may not be cached, and Cacheable exists to better represent cases when it's not. I'm questioning the second arg, which is presented as a raw SocketMessage.

Perhaps the solution, then, is to make the second argument a type similar to Cacheable<SocketMessage, ulong> - though, of course, without the ability to download it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants