// Runbot task public async Task RunBot() { _client = new DiscordSocketClient(); // Define _client _commands = new CommandService(); // Define _commands _services = new ServiceCollection() // Define _services .AddSingleton(_client) .AddSingleton(_commands) .BuildServiceProvider(); string botToken = "TOKEN"; // Make a string for the token _client.Log += Log; // Logging _client.MessageReceived += MessageReceived; _client.Ready += Ready; _client.JoinedGuild += JoinGuild; _client.LeftGuild += LeftGuild; _client.UserJoined += userjoin; _client.UserLeft += userleave; await RegisterCommandsAsync(); // Call registercommands await _client.LoginAsync(TokenType.Bot, botToken); // Log into the bot user Timer t = new Timer(86400000); // 1 sec = 1000, 60 sec = 60000 t.AutoReset = true; t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed); t.Start(); await _client.StartAsync(); // Start the bot user report = new DailyReport() { dayOfReport = DateTime.Now, insultsSent = 0, commandsRan = 0, guildsJoined = 0, guildsLeft = 0, messagesSent = 0, usersJoined = 0, usersLeft = 0 }; await _client.SetGameAsync("gr!help"); // Set the game the bot is playing await TakeCommand(); await Task.Delay(-1); // Delay for -1 to keep the console window opened }
private async void sendReport(bool isDaily) { SocketGuild supportServer = _client.GetGuild(543324164191289354); SocketTextChannel logChannel = (SocketTextChannel)supportServer.GetChannel(543537906854264842); string json = JsonConvert.SerializeObject(report, Formatting.Indented); File.WriteAllText("DailyReports\\" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + " Report.json", json); await logChannel.SendFileAsync("DailyReports\\" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + " Report.json", "Daily report for " + DateTime.Now); if (isDaily) { report = new DailyReport() { dayOfReport = DateTime.Now, insultsSent = 0, commandsRan = 0, guildsJoined = 0, guildsLeft = 0, messagesSent = 0, usersJoined = 0, usersLeft = 0 }; } }