Adding Admin Commands for Purging Messages
This commit is contained in:
parent
2c88b7f1c9
commit
4e59ccb85d
@ -12,6 +12,7 @@
|
||||
<e p="Discord" t="Include">
|
||||
<e p="DiscordConnect.cs" t="Include" />
|
||||
<e p="Modules" t="Include">
|
||||
<e p="AdminCommands.cs" t="Include" />
|
||||
<e p="InfoCommands.cs" t="Include" />
|
||||
</e>
|
||||
<e p="Services" t="Include">
|
||||
|
||||
39
ChaosBot/Discord/Modules/AdminCommands.cs
Normal file
39
ChaosBot/Discord/Modules/AdminCommands.cs
Normal file
@ -0,0 +1,39 @@
|
||||
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}]>.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user