You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently in the process of porting over a bot of mine from TypeScript to C#, I've started with a Service Worker / BackgroundService template and have been moving over my code and refactoring it to fit C# better.
The way my bot works is it's entirely passive, reading each message and finding links to create embeds of, and I've noticed with Discord.Net that there's an emphasis to keep the code in the MessageReceived event handler to be sort and quick as it blocks the main "gateway" thread, where as in Discord.JS the messageCreate event seems to always be run asynchronously and can process as much as the node event loop can seem to handle at once.
I've had a couple of questions spawn from this fact.
My current MessagedRecieved Handler looks like this:
privateTaskHandleMessageAsync(SocketMessagesocketMessage){Task.Run(async()=>{if(socketMessageis not SocketUserMessagemessage){return;}// Ignore Messages from Bots (including this one) and Webhookif(socketMessage.Author.IsBot||socketMessage.Author.IsWebhook){return;}varresults=await_siteManager.Match(message.Content);foreach(var(site,match)inresults){_logger.LogDebug("Matched link \"{Match}\" to site {Site}",match,site);varresponse=await_siteManager.Process(site,match,message);if(responseisnull){_logger.LogDebug("Failed to process match \"{Match}\" of site {Site}",match,site);continue;}await_messageManager.Send(message,response);}});returnTask.CompletedTask;}
Would this be the recommended way to asynchronously process each message that comes in? Or is there a preferred approach in Discord.Net to handle this?
I have noticed things like CommandHandlers and such that are build in for building responses to specific commands, however I'm need to process each message that comes in and check for links.
My other main question, is there any way to refresh / refetch a message object? In my main my code there is a point where I wait for a message to fully load and the refetch it, I'm having a bit of trouble finding any documentation on how to get a message from discord either via ID or refresh the existing SocketUserMessage object.
If anyone as well has any general tips on any recommended ways that Discord.Net handles things over Discord.JS, I'd also appreciate that too.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm currently in the process of porting over a bot of mine from TypeScript to C#, I've started with a Service Worker / BackgroundService template and have been moving over my code and refactoring it to fit C# better.
The way my bot works is it's entirely passive, reading each message and finding links to create embeds of, and I've noticed with Discord.Net that there's an emphasis to keep the code in the MessageReceived event handler to be sort and quick as it blocks the main "gateway" thread, where as in Discord.JS the messageCreate event seems to always be run asynchronously and can process as much as the node event loop can seem to handle at once.
I've had a couple of questions spawn from this fact.
My current MessagedRecieved Handler looks like this:
Full file here: https://github.com/Sn0wCrack/saucybot-discord/blob/develop/v2/SaucyBot/Worker.cs
Would this be the recommended way to asynchronously process each message that comes in? Or is there a preferred approach in Discord.Net to handle this?
I have noticed things like CommandHandlers and such that are build in for building responses to specific commands, however I'm need to process each message that comes in and check for links.
My other main question, is there any way to refresh / refetch a message object? In my main my code there is a point where I wait for a message to fully load and the refetch it, I'm having a bit of trouble finding any documentation on how to get a message from discord either via ID or refresh the existing SocketUserMessage object.
If anyone as well has any general tips on any recommended ways that Discord.Net handles things over Discord.JS, I'd also appreciate that too.
Beta Was this translation helpful? Give feedback.
All reactions