#Addressing WARN An event handler took too long to execute

1 messages · Page 1 of 1 (latest)

runic shore
#

Noticed I'm getting warnings on my event handlers.

[2022-10-23 13:19:58 +00:00] [104 /EventHandler] [Warn ] An event handler for READY took too long to execute. 
[2022-10-23 13:51:41 +00:00] [104 /EventHandler] [Warn ] An event handler for GUILD_MEMBER_ADD took too long to execute. 
[2022-10-23 14:26:02 +00:00] [104 /EventHandler] [Warn ] An event handler for GUILD_MEMBER_ADD took too long to execute. 

Figured I'd try to dispatch the work to another thread to solve the problem, is this the recommended approach for discord? Thanks

discord.GuildMemberAdded += async (s, e) => //event fired when a member joins
   {
       await Task.Run(async () => {
          //do the work here
       });
   };
snow barn
#

Awaiting Task.Run just waits for the task to complete, putting you back at square one. You get this error message because the execution time of your handler exceeds the 1s timeout, and so any exceptions thrown after that point will not be caught by the library.

#

Consider shortening the time it takes to execute your work, or even pushing your logic into a self-contained service.