예제 #1
0
 private async Task Ready()
 {
     if (!_commandManager.AreCommandsLoaded)
     {
         _ = Task.Run(async() =>
         {
             var debugGuild = _commandManager.GetDebugGuild(client);
             var commands   = _commandManager.LoadCommands();
             foreach (var cmd in commands)
             {
                 if (debugGuild != null)
                 {
                     await debugGuild.CreateApplicationCommandAsync(cmd.SlashCommand);
                 }
                 else
                 {
                     await client.CreateGlobalApplicationCommandAsync(cmd.SlashCommand);
                 }
             }
             if (debugGuild != null)
             {
                 await debugGuild.BulkOverwriteApplicationCommandAsync(commands.Select(x => x.SlashCommand).ToArray());
             }
             else
             {
                 await client.BulkOverwriteGlobalApplicationCommandsAsync(commands.Select(x => x.SlashCommand).ToArray());
             }
         });
     }
 }
예제 #2
0
        private async Task ReadyHandler()
        {
            _logger.LogInformation("Client connected.");
            _isRunning = true;

            try
            {
                await _client.BulkOverwriteGlobalApplicationCommandsAsync(Array.Empty <ApplicationCommandProperties>());
            } catch (Exception ex)
            {
                _logger.LogError(ex, "Something went wrong while overwriting global application commands.");
            }
            foreach (var guild in _client.Guilds)
            {
                try
                {
                    await JoinGuild(guild);
                } catch (Exception ex)
                {
                    _logger.LogError(ex, $"Something went wrong while handling guild join for {guild.Id}.");
                }
            }

            if (_firstReady)
            {
                _firstReady = false;
                try
                {
                    await _scheduler.ExecuteAsync();
                } catch (Exception ex)
                {
                    _logger.LogCritical(ex, "Something went wrong while starting the scheduler timer.");
                }
                try
                {
                    await _punishments.ExecuteAsync();
                } catch (Exception ex)
                {
                    _logger.LogCritical(ex, "Something went wrong while starting the punishmenthandling timer.");
                }
            }
        }