示例#1
0
        private async Task Start()
        {
            var config = new DiscordSocketConfig
            {
                TotalShards         = 1,
                ExclusiveBulkDelete = true
            };

            EnsureBotConfigExists();
            EnsureServerConfigExists();
            serverConfig = ServerConfig.Load();

            using (var services = ConfigureServices(config))
            {
                var client = services.GetRequiredService <DiscordShardedClient>();

                client.ShardReady += ReadyAsync;
                client.Log        += LogAsync;

                await services.GetRequiredService <CommandHandler>().InitializeAsync();

                await client.LoginAsync(TokenType.Bot, Configuration.Load().Token);

                await client.StartAsync();

                await Task.Delay(-1);
            }
        }
        private async Task CheckRichestPerson(SocketGuild guild)
        {
            var newRichestPerson = (await _da.GetTopXGold(1)).FirstOrDefault()?.UserID ?? 0;

            if (newRichestPerson == 0)
            {
                return;
            }

            var currentRichestPerson = GetCurrentRichestPerson(guild);

            if (currentRichestPerson == null || newRichestPerson != currentRichestPerson.Id)
            {
                var guildRole = (IRole)guild.GetRole(ServerConfig.Load().richRole);
                await guild.GetUser(newRichestPerson).AddRoleAsync(guildRole);

                if (currentRichestPerson != null)
                {
                    await currentRichestPerson.RemoveRoleAsync(guildRole);
                }
            }
        }
 public SocketGuildUser GetCurrentRichestPerson(SocketGuild guild) =>
 guild.Users.FirstOrDefault(x => x.Roles.Any(y => y.Id == ServerConfig.Load().richRole));