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
This is my current code for my bot:
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<>ServiceBase<> and IService<>IService<>This is my current code for my bot:
public static Task Main()
=> new Program().MainAsync();
private async Task MainAsync()
{
try
{
var client = new DiscordSocketClient();
using var host = Host.CreateDefaultBuilder()
.ConfigureServices((_, services) =>
{
services
.AddSingleton(client)
.AddSingleton(i => new InteractionService(i.GetRequiredService<DiscordSocketClient>()))
.AddSingleton<InteractionHandler>()
.AddTransient<ITestService, TestService>();
services.AddGrpc();
services.AddMagicOnion();
}
).Build();
await RunAsync(host);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
private async Task RunAsync(IHost host)
{
using var serviceScope = host.Services.CreateScope();
var serviceProvider = serviceScope.ServiceProvider;
var commands = serviceProvider
.GetRequiredService<InteractionService>();
var client = serviceProvider
.GetRequiredService<DiscordSocketClient>();
await serviceProvider
.GetRequiredService<InteractionHandler>()
.InitializeAsync();
await client.LoginAsync(TokenType.Bot, Token);
await client.StartAsync();
client.Log += Log;
client.Ready += async () =>
{
await commands.RegisterCommandsToGuildAsync(DiscordGuildId);
};
await Task.Delay(-1);
} public static Task Main()
=> new Program().MainAsync();
private async Task MainAsync()
{
try
{
var client = new DiscordSocketClient();
using var host = Host.CreateDefaultBuilder()
.ConfigureServices((_, services) =>
{
services
.AddSingleton(client)
.AddSingleton(i => new InteractionService(i.GetRequiredService<DiscordSocketClient>()))
.AddSingleton<InteractionHandler>()
.AddTransient<ITestService, TestService>();
services.AddGrpc();
services.AddMagicOnion();
}
).Build();
await RunAsync(host);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
private async Task RunAsync(IHost host)
{
using var serviceScope = host.Services.CreateScope();
var serviceProvider = serviceScope.ServiceProvider;
var commands = serviceProvider
.GetRequiredService<InteractionService>();
var client = serviceProvider
.GetRequiredService<DiscordSocketClient>();
await serviceProvider
.GetRequiredService<InteractionHandler>()
.InitializeAsync();
await client.LoginAsync(TokenType.Bot, Token);
await client.StartAsync();
client.Log += Log;
client.Ready += async () =>
{
await commands.RegisterCommandsToGuildAsync(DiscordGuildId);
};
await Task.Delay(-1);
}


