DiscordMessage.Timestamp throws NullReferenceException
Created by: 13xforever
Summary
If you try to access Timestamp
property of a message that is not in the client's cache, it will throw NullReferenceException
.
Details
I am using DSharpPlus 4.0.0-beta-00469, and noticed this in the handler that tries to moderate the reaction usage.
I think this property should be nullable and return null
in case there's not data about the creation timestamp available, it will allow to handle this situation gracefully instead of wrapping everything in try{} catch{}
.
EditedTimestamp
and MentionedUsers
have similar issues in that they throw if the message wasn't edited / doesn't contain mentions.
System.ArgumentNullException: Value cannot be null.
Parameter name: input
at DSharpPlus.Entities.DiscordMessage.get_Timestamp()
at CompatBot.EventHandlers.Starbucks.Handler(MessageReactionAddEventArgs args) in F:\Work\git\discord-bot-net\CompatBot\EventHandlers\Starbucks.cs:line 29
Steps to reproduce
- create a handler that can receive information about old messages
- try to access
Timestamp
property of the message - cry, I guess
Notes
As a workaround you can use .CreationTimestamp
property or manually fetch the complete message information