public async Task DelDM(int msgcount) { IDMChannel dm = await Context.User.GetOrCreateDMChannelAsync(); IEnumerable <IMessage> msgs = dm.GetMessagesAsync(msgcount).FlattenAsync().Result; foreach (IMessage msg in msgs) { await dm.DeleteMessageAsync(msg); } IEmote emote = new Emoji("✅"); await Context.Message.AddReactionAsync(emote); }
public async Task ClearDM(int messageCount) { await Context.Message.DeleteAsync(); IDMChannel dmChannel = await Context.Message.Author.GetOrCreateDMChannelAsync(); IEnumerable <IMessage> messages = await dmChannel.GetMessagesAsync(messageCount).FlattenAsync(); List <IMessage> filteredMessages = messages.ToList <IMessage>(); for (int i = 0; i < filteredMessages.Count; i++) { TimeSpan difference = DateTimeOffset.Now.Subtract(filteredMessages[i].CreatedAt); if (filteredMessages[i].Author.Id == Context.User.Id || difference.TotalMilliseconds >= (double)1203552000) { filteredMessages.RemoveAt(i); i--; } else { await filteredMessages[i].DeleteAsync(); } } }