示例#1
0
        public async Task MainAsync()
        {
            _client = new DiscordSocketClient(new DiscordSocketConfig
            {
                LogLevel = LogSeverity.Info
            });

            _client.Log   += Log;
            _client.Ready += async() => { IsLoaded = true; };

            try
            {
                await _client.LoginAsync(TokenType.Bot, _token);

                await _client.StartAsync();
            }
            catch (HttpException e)
            {
                _Core.WriteLog("연결을 할 수 없습니다 : " + e);
                _client.Dispose();
            }


            await Task.Delay(-1);
        }
示例#2
0
        public async void Run()
        {
            try
            {
                int TotalPlayer = 0;
                _Core.discord.DeleteMessage(10);
                for (int i = 0; i < servers.Count; i++)
                {
                    servers[i]             = GetServerStats(servers[i]);
                    TotalPlayer           += servers[i].Players.Count;
                    servers[i].LastMessage = await _Core.discord.SendEmbedAsync(GetEmbed(servers[i]));

                    await Task.Delay(300);
                }
                _Core.discord.SetGameAsync(TotalPlayer);

                while (true)
                {
                    await Task.Delay(Delay * 1000);

                    TotalPlayer = 0;
                    for (int i = 0; i < servers.Count; i++)
                    {
                        servers[i]   = GetServerStats(servers[i]);
                        TotalPlayer += servers[i].Players.Count;
                        if (0 < DateTime.UtcNow.CompareTo(servers[i].LastMessage.Timestamp.AddDays(10).DateTime))
                        {
                            await servers[i].LastMessage.DeleteAsync();
                            servers[i].LastMessage = await _Core.discord.SendEmbedAsync(GetEmbed(servers[i]));
                        }
                        else
                        {
                            _Core.discord.EditEmbedAsync(GetEmbed(servers[i]), servers[i].LastMessage);
                        }

                        await Task.Delay(300);
                    }
                    _Core.discord.SetGameAsync(TotalPlayer);
                }
            }
            catch (Exception e)
            {
                _Core.WriteLog("오류가 발생 했습니다 : " + e);
            }
        }