hopefully fix random disconnects that don't try to restart?

This commit is contained in:
sam 2024-10-25 03:35:37 +02:00
parent 9302ba200f
commit a5a8bb34c6
Signed by: sam
GPG key ID: 5F3C3C1B3166639D

View file

@ -17,13 +17,26 @@ using Remora.Discord.Gateway.Results;
namespace Catalogger.Backend.Bot;
public class ShardedDiscordService(ShardedGatewayClient client, IHostApplicationLifetime lifetime)
: BackgroundService
public class ShardedDiscordService(
ILogger logger,
ShardedGatewayClient client,
IHostApplicationLifetime lifetime
) : BackgroundService
{
private readonly ILogger _logger = logger.ForContext<ShardedDiscordService>();
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var result = await client.RunAsync(stoppingToken);
if (result.Error is GatewayError { IsCritical: true })
lifetime.StopApplication();
while (!stoppingToken.IsCancellationRequested)
{
_logger.Information("Starting sharded Discord client");
var result = await client.RunAsync(stoppingToken);
_logger.Information("Discord client finished running");
if (result.Error is GatewayError { IsCritical: true })
{
lifetime.StopApplication();
break;
}
}
}
}