hopefully fix random disconnects that don't try to restart?
This commit is contained in:
parent
9302ba200f
commit
a5a8bb34c6
1 changed files with 18 additions and 5 deletions
|
|
@ -17,13 +17,26 @@ using Remora.Discord.Gateway.Results;
|
||||||
|
|
||||||
namespace Catalogger.Backend.Bot;
|
namespace Catalogger.Backend.Bot;
|
||||||
|
|
||||||
public class ShardedDiscordService(ShardedGatewayClient client, IHostApplicationLifetime lifetime)
|
public class ShardedDiscordService(
|
||||||
: BackgroundService
|
ILogger logger,
|
||||||
|
ShardedGatewayClient client,
|
||||||
|
IHostApplicationLifetime lifetime
|
||||||
|
) : BackgroundService
|
||||||
{
|
{
|
||||||
|
private readonly ILogger _logger = logger.ForContext<ShardedDiscordService>();
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
var result = await client.RunAsync(stoppingToken);
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
if (result.Error is GatewayError { IsCritical: true })
|
{
|
||||||
lifetime.StopApplication();
|
_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue