Do something when event fired
Hello Im kinda new with programming stuff etc and i would like to ask how can I call a function by event or do something when its fired cause actually my event skill are very low.
If it matters, i'm trying to create a discord bta using dsharpplus, where there are events that i have trouble handling.
currently the code I have is the one below, but this one gives me an error:
Severity Code Description Project File Row Skip status
Error CS1643 Not all paths in code return value in lambda expression of type "AsyncEventHandler<DiscordClient, MessageCreateEventArgs>" MeowBot D:\Vs projects\MeowBot\Program.cs 168 Active
and its doesnt give me any log in sonsole
3 Replies
https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.threading.asynceventhandler-1?view=visualstudiosdk-2022 AsyncEventHandler returns a Task so you need to make the handling async
AsyncEventHandler Delegate (Microsoft.VisualStudio.Threading)
An asynchronous event handler.
But consider handling it either in a delegate variable or method so you can unsubscribe from the event. Using an anonymous function like this, you lose control over the handler function after subscribing to the event so you cannot reference it later to unsubscribe.
Thx bro