Changing the purge command

pull/8/head
sgoudham 4 years ago
parent acc719c026
commit 9eb8b2a036

@ -1,4 +1,5 @@
import asyncio import datetime
from datetime import timedelta
from discord import Member from discord import Member
from discord.ext import commands from discord.ext import commands
@ -79,28 +80,16 @@ class Moderation(commands.Cog):
@bot_has_guild_permissions(manage_messages=True) @bot_has_guild_permissions(manage_messages=True)
async def purge(self, ctx, amount: int = None): async def purge(self, ctx, amount: int = None):
"""Purge Messages from Channel""" """Purge Messages from Channel"""
if not amount:
amount = 100 if 0 < amount <= 100:
with ctx.channel.typing():
if amount > 100: await ctx.message.delete()
await ctx.send("Sorry! You can only purge up to **100** messages at a time!") deleted = await ctx.channel.purge(limit=amount, after=datetime.datetime.utcnow() - timedelta(days=14))
elif amount <= 100:
channel = ctx.message.channel await ctx.send(f"Deleted **{len(deleted):,}** messages.", delete_after=5)
messages = []
else:
async for message in channel.history(limit=amount): await ctx.send("The amount provided is not between **0** and **100**")
messages.append(message)
try:
await channel.delete_messages(messages)
msg = await ctx.send(f"{ctx.author.mention} {amount} messages deleted!")
except Exception as ex:
print(ex)
await ctx.send("Error! {}".format(ex))
# Let the user read the message for 5 seconds
await asyncio.sleep(5)
# Delete the message
await msg.delete()
def setup(bot): def setup(bot):

Loading…
Cancel
Save