[Bug]: MessageUpdated Event is Triggert if Uploading a File
Spielepapagei opened this issue · 1 comments
Check The Docs
- I double checked the docs and couldn't find any useful information.
Verify Issue Source
- I verified the issue was caused by Discord.Net.
Check your intents
- I double checked that I have the required intents.
Description
I get an exaption when the bot sends an attchment to the user without a message.Content
. Immediately after that a MessageUpdate
event is triggered where everything is null.
Version
3.9.0
Working Version
No response
Logs
12:12:12 Gateway A MessageUpdated handler has thrown an unhandled exception.:
System.NullReferenceException: Object reference not set to an instance of an object.
at Squid.Components.TicketPostMessages.ModifyMessage(IdMessageModel messageModel, SocketMessage message, SocketThreadChannel thread)
at Squid.Modules.TicketMessageUpdated.OnMessageUpdate(Cacheable2 ignore, SocketMessage message, ISocketMessageChannel channel) at Discord.EventExtensions.InvokeAsync[T1,T2,T3](AsyncEvent
1 eventHandler, T1 arg1, T2 arg2, T3 arg3)
at Discord.WebSocket.DiscordSocketClient.TimeoutWrap(String name, Func`1 action)
Sample
//Get the Attachments(Images and Files) and send a Message to the User.
var attachments = message.Attachments.Select(x => x.Url).ToList();
IUserMessage dmMessage;
if (attachments.Count > 0)
{
dmMessage = await user.SendMessageAsync($"**[Support]** {message.Author.Username} > {message.Content} >>> {attachments.Aggregate((x, y) => x + "\n" + y)}");
}
else
{
dmMessage = await user.SendMessageAsync($"**[Support]** {message.Author.Username} > {message.Content}");
}
return dmMessage;
//Event Client.MessageUpdated
// This is the Line that coast the exaptation
await dmMessage.ModifyAsync(a => a.Content = $"**[Support]** {message.Author.Username} > {message.Content} >>> {attachments.Aggregate((x, y) => x + "\n" + y)}");
Packages
Discord.Net" Version="3.9.0"
Logging.Net" Version="1.0.9"
Microsoft.EntityFrameworkCore Version="6.0.10"
Pomelo.EntityFrameworkCore.MySql Version="6.0.2"
With how long ago this was I'd imagine you already either solved this or moved on, but I believe this might be caused because Discord applies attachments on a message in a separate event, which is, technically, a message update.
I'd suggest you simply return
on MessageUpdate if contents that shouldn't be null are null.