39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using System;
|
|
using Discord;
|
|
using System.Text;
|
|
using Discord.Commands;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
using Microsoft.Extensions.Configuration;
|
|
using NLog;
|
|
|
|
|
|
namespace ChaosBot.Discord.Modules
|
|
{
|
|
public class AdminCommands : ModuleBase
|
|
{
|
|
private static readonly Logger _logger = Program._logger;
|
|
|
|
|
|
[Command("clear")]
|
|
[Alias("purge")]
|
|
[RequireBotPermission(GuildPermission.ManageMessages)]
|
|
[RequireUserPermission(GuildPermission.ManageMessages)]
|
|
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($"InfoCommands.InfoCommand: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
|
}
|
|
}
|
|
}
|
|
} |