C
C#2y ago
majdii

❔ Discord Bot Service Problem

Does anyone know how to register that service properly?
20 Replies
Jayy
Jayy2y ago
Need to add HttpClientFactory on startup It's a nuget i believe
majdii
majdiiOP2y ago
I have all needed packages installed I belive
Jayy
Jayy2y ago
did you add HttpClientFactory to startup? let me see
majdii
majdiiOP2y ago
Do you want to see my project packages installed If I understood you well? Or my Program.cs file? I'm pretty sure, the problem is that I have no IHtmlClientFactory added to my service, however i dont how to add it properly
majdii
majdiiOP2y ago
This is how my Program.cs looks for now
majdii
majdiiOP2y ago
However, if i try to add this line: services.AddSingleton<IHttpClientFactory>(); ,this error occurs
majdii
majdiiOP2y ago
Which means if i understand well, that in services.AddSingleton i cant pass Interface, and i need to pass something what inherits from it And here is where my knowledge ends xD
Pobiega
Pobiega2y ago
you should be using the AddHttpClient() extension method
majdii
majdiiOP2y ago
Can you explain what do you mean?
Pobiega
Pobiega2y ago
services.AddHttpClient(); you shouldn't be manually registering it
Jayy
Jayy2y ago
they already have that ohh they arent using th ehost lol
majdii
majdiiOP2y ago
How should I do it then?
Pobiega
Pobiega2y ago
kekw
Pobiega
Pobiega2y ago
Pobiega
Pobiega2y ago
you are making a host, but then ignoring it
Jayy
Jayy2y ago
Jayy
Jayy2y ago
what are you doing with host here
majdii
majdiiOP2y ago
Lmao xD it should be await host.RunAsync(); and bot should start?
Jayy
Jayy2y ago
follow the docs for your discord lib
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server