NRE in DiscordApiClient due to insufficient null handling
See original GitHub issueSummary
Clearing a DiscordMessageBuilder of Components without adding any stickers to it causes an NRE when trying to send it via a DiscordRestClient (probably also normally, have only tested with a rest client)
Details
I have encountered it in every version since presumably the commit a1e5becd2dbd4bfdd37caa82116b1596b389a6e3.
The issue is that invoking ClearComponents sets the Sticker to default
here
https://github.com/DSharpPlus/DSharpPlus/blob/94717715ce97651187c32655ae70f298801c12c8/DSharpPlus/Entities/Channel/Message/DiscordMessageBuilder.cs#L229-L236
But then when trying to send the Message in DiscordApiClient it is not handled when the sticker itself should be null
https://github.com/DSharpPlus/DSharpPlus/blob/94717715ce97651187c32655ae70f298801c12c8/DSharpPlus/Net/Rest/DiscordApiClient.cs#L1358-L1367
Obviously this then also causes the message to fail to send.
This code snippet should be enough to reproduce the issue
var bot = new DiscordRestClient(...);
var messageBuilder = new DiscordMessageBuilder();
messageBuilder.WithContent("Test");
messageBuilder.ClearComponents();
await bot.CreateMessageAsync(<channel_id>, messageBuilder);
Issue Analytics
- State:
- Created 7 months ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
yes, v5 will use nullability annotations
#1481 Has fixed this, thank you