Discord.Net + MagicOnion, heheh
Hey!
So I am working on a discord bot that I want to intergrate into a server using websockets, I found MagicOnion and wanted to test it out, but I can only find documentation to how to use it with Asp.Net.
Does anyone know how I would implement it with Discord.Net?
I have a test service that uses the
ServiceBase<>
and IService<>
This is my current code for my bot:
63 Replies
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
$mains
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
The possible signatures for
Main
are public
is not required (can be any accessibility).
Top-level statements are compiled into a Main
method and will use an appropriate signature depending on the body.
https://docs.microsoft.com/en-US/dotnet/csharp/fundamentals/program-structure/main-command-lineMain() and command-line arguments - C#
Learn about Main() and command-line arguments. The 'Main' method is the entry point of an executable program.
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
But idk if this solved my issue tho, having the bot be a websocket server aswell?
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
I really appreciate the tips on how to simplify the code, don't get me wrong.
My original question was how I could implement MagicOnion, a websocket library into the bot.
I wanted the bot to act like a websocket server for other clients to connect into if that makes sense.
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Ahhh okay, I'll give it a try.
So just try running most of it from the Main method?
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
So like this instead?
Hey!
I still need some help with this.
I've done some changes, but I can still not get it to work.
This is my current code: https://pastecord.com/olofinitob
All help is deeply appreciated.
My goal is to send data from and to a game server, but I want the websocket server to be on the discord bot.
So I don't need to do:
- Game Server -> Magic Onion Server -> Discord Bot
- Wise Versa
How can I do so?
It looks like Magic Onion is mostly made for Asp.Net apps, but this is a console app
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Am I able to run the bot on a ASP app?
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
I've worked with like ASP api's, etc before.
But never something like this lmao
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
aahh
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
So I was basically trying to make an ASP app in a console app
ish
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
without the web server part
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Does this look more correct then?
https://pastecord.com/duhebusywo.cs
Now its running on an asp app instead
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
But background service are basically just for starting something to run in the background right?
Its just a way for it to auto load when the program starts ish?
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Why?
Whats up with using the logger?
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Okay, I've never actually heard abt that lmao
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Using the $ is not recommended?
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
ahhhh
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Ah okay, and I shouldn't be the one filling in the template
{}
, basicallyUnknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Ahhhhhhh
Bro is filling my mind, I feel my brain is expanding 😂
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
And there you talk about how to do it correctly when it comes to logging?
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Ahh okay, I'll have a read on it.
I've fallen really for C# and just trying to learn as much as I can lol
But its not always the easiest 😅
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Okay wtf
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
😂
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
So basically.
I make a log method.
Like this:
and when I want to use it I can do smth like:
LogUserError(logger, _client.CurrentUser.UserName);
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
Ahh, and this is the most official and recommended way of doing logging ig?
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
CustomEventName 🤔
So instead of doing
_logger.LogInformation("{Username} has hit an error", _client.CurrentUser.UserName)
, I should do this.Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
🥹
So basically like this:
Log.BotStarted(_logger, _client.CurrentUser.Username);
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
ahhh, went training so didn't see the last messsages.
Basically waht it does is that the source generator detects this
[LoggerMessage(.........)]
and then creates the code inside the method automatically.
Right?TeBeCo
and
[LoggerMessage(.........]
is what's detected by the source generatorQuoted by
<@689473681302224947> from #Discord.Net + MagicOnion, heheh (click here)
React with ❌ to remove this embed.
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
TeBeCo
then it's using all the properties and generates sub optimized code to properly call the logger
Quoted by
<@689473681302224947> from #Discord.Net + MagicOnion, heheh (click here)
React with ❌ to remove this embed.
So I should make
[LoggerMessage]
for each logging I do?Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View