Adding new clear command in new Module / Fodler based system.
This commit is contained in:
parent
8a9d686617
commit
3349c64f37
35
ChaosBot/Discord/Modules/Admin/Clear.cs
Normal file
35
ChaosBot/Discord/Modules/Admin/Clear.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using ChaosBot.Discord.PreConditions;
|
||||
using NLog;
|
||||
|
||||
namespace ChaosBot.Discord.Modules.Admin
|
||||
{
|
||||
public class Clear : ModuleBase
|
||||
{
|
||||
private static readonly ILogger _logger = Program.Logger;
|
||||
|
||||
[Command("clear")]
|
||||
[Alias("purge")]
|
||||
[CheckCommandPerm]
|
||||
public async Task ClearCommand(int msgtoDelete = 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
IEnumerable<IMessage> messages = await Context.Channel.GetMessagesAsync(msgtoDelete + 1).FlattenAsync();
|
||||
await ((ITextChannel) Context.Channel).DeleteMessagesAsync(messages);
|
||||
const int delay = 3000;
|
||||
IUserMessage m = await ReplyAsync($"{msgtoDelete} messages deleted.");
|
||||
await Task.Delay(delay);
|
||||
await m.DeleteAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error($"AdminCommands.ClearCommand: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user