protected override async Task ExecuteAsync(CancellationToken stoppingToken) { Result checkSlashSupport = _slashService.SupportsSlashCommands(); if (!checkSlashSupport.IsSuccess) { LogSlashCommandsNotSupported(checkSlashSupport.Error.Message); return; } _ = Snowflake.TryParse(_options.DiscordDevServerId, out Snowflake? guild); Result updateSlash = await _slashService.UpdateSlashCommandsAsync(guild, null, stoppingToken); if (!updateSlash.IsSuccess) { LogSlashCommandsUpdateError(updateSlash.Error.Message); return; } Result runResult = await _gatewayClient.RunAsync(stoppingToken); if (!runResult.IsSuccess && !stoppingToken.IsCancellationRequested) { switch (runResult.Error) { case ExceptionError exe: LogGatewayConnectionException(exe.Exception, exe.Message); break; case GatewayWebSocketError: case GatewayDiscordError: LogGatewayError(runResult.Error.Message); break; default: LogUnknownError(runResult.Error.Message); break; } } }
public async Task <Result> RespondAsync(IGuildCreate gatewayEvent, CancellationToken ct = new CancellationToken()) { var slashSupport = _slash.SupportsSlashCommands(); if (!slashSupport.IsSuccess) { _logger.LogWarning("The registered commands of the bot don't support slash commands: {Reason}", slashSupport.Error?.Message); return(Result.FromError(slashSupport.Error)); } var update = await _slash.UpdateSlashCommandsAsync(gatewayEvent.ID, ct); if (!update.IsSuccess) { _logger.LogWarning("Failed to update slash commands: {Reason}", update.Error?.Message); return(Result.FromError(update.Error)); } return(Result.FromSuccess()); }