public static Task Discord_Ready(DiscordClient dc, DSharpPlus.EventArgs.ReadyEventArgs args) { _ = Task.Run(async() => { dc.Logger.LogInformation("Looking for Reminders"); var output = await SQLC.GetReminders(); if (output.Any()) { foreach (var item in output) { long ID = item.ID; long ChannelID = item.ChannelID; long Date = item.Date; string Reminder = item.Reminder; try { DiscordGuild Guild = await dc.GetGuildAsync(GuildID); DiscordMember member = await Guild.GetMemberAsync((ulong)ID); DiscordChannel channel = Guild.GetChannel((ulong)ChannelID); DateTime dateTime = DateTime.FromBinary(Date); if (dateTime < DateTime.Now) { await SQLC.DeleteRemindersWithDate(Date); await channel.SendMessageAsync($":alarm_clock:, {member.Mention} you wanted me to remind you the following but I'm Late:\n\n{Reminder}"); continue; } _ = Task.Run(async() => { await Task.Delay((int)dateTime.Subtract(DateTime.Now).TotalMilliseconds); DiscordGuild Guild = await dc.GetGuildAsync(GuildID); DiscordMember member = await Guild.GetMemberAsync((ulong)ID); DiscordChannel channel = Guild.GetChannel((ulong)ChannelID); await channel.SendMessageAsync($":alarm_clock:, {member.Mention} you wanted me to remind you the following:\n\n{Reminder}"); await SQLC.DeleteRemindersWithDate(Date); }); } catch (Exception) { await SQLC.DeleteRemindersWithDate(Date); continue; } } dc.Logger.LogInformation("Found Reminders and started them"); } else { dc.Logger.LogInformation("No Reminders found"); } dc.Logger.LogInformation("Looking for muted Members"); output = await SQLC.GetTempmutes(); if (output.Any()) { foreach (var item in output) { long ID = item.ID; long Date = item.Date; try { DiscordGuild Guild = await dc.GetGuildAsync(GuildID); DiscordRole MutedRole = Guild.GetRole(Program.MutedRole); DiscordMember member = await Guild.GetMemberAsync((ulong)ID); DateTime dateTime = DateTime.FromBinary(Date); if (dateTime < DateTime.Now) { await SQLC.DeleteTempmutesWithID(ID); await member.RevokeRoleAsync(MutedRole); continue; } _ = Task.Run(async() => { try { await Task.Delay((int)dateTime.Subtract(DateTime.Now).TotalMilliseconds); DiscordGuild Guild = await dc.GetGuildAsync(GuildID); DiscordRole MutedRole = Guild.GetRole(Program.MutedRole); DiscordMember member = await Guild.GetMemberAsync((ulong)ID); var PS = await SQLC.GetPlayer(member.Id); PS.Muted = false; await PS.Save(); await member.RevokeRoleAsync(MutedRole); await SQLC.DeleteTempmutesWithID(ID); } catch (Exception) { dc.Logger.LogInformation($"Failed the Tempmute process for {member.Username + member.Discriminator}"); } }); } catch (Exception) { await SQLC.DeleteTempmutesWithID(ID); continue; } } dc.Logger.LogInformation("Found muted Members and starting them"); } else { dc.Logger.LogInformation("No muted Members found"); } while (true) { foreach (var Status in Statuses) { DiscordActivity activity = new DiscordActivity { ActivityType = ActivityType.Playing, Name = Status }; await dc.UpdateStatusAsync(activity, UserStatus.DoNotDisturb); dc.Logger.LogInformation("Status Update"); await Task.Delay(120000); } } }); return(Task.CompletedTask); }