Answers for "Discord Bot C# bulk deleting"

C#
0

Discord Bot C# bulk deleting

[Command("remove")] 
[Aliases("clear", "cleanse", "purge")]
[RequirePermissions(Permissions.ManageMessages)]
public async Task RemoveMessages(CommandContext ctx, int count = 0) {
	int limit = 100; // Can be changed

	// Get & Delete messages
	var messages = await ctx.Channel.GetMessagesAsync((count + 1 > limit ? limit : count + 1)).ConfigureAwait(false);
	await ctx.Channel.DeleteMessagesAsync(messages);

	// Limit exceded message
	if (count > limit) {
		await ctx.Channel.SendMessageAsync($"Too many messages to delete! ({count})\nOnly deleted 100").ConfigureAwait(false);
	}
}
Posted by: Guest on September-23-2021

C# Answers by Framework

Browse Popular Code Answers by Language