Clear Messages Changes
- New approach
This commit is contained in:
Logan Cusano
2022-04-09 21:39:44 -04:00
parent 44d027ab8c
commit 35e19ee83f

View File

@@ -1,6 +1,9 @@
import logging
from discord.ext import commands
import asyncio
LOGGER = logging.getLogger("Discord_Radio_Bot.LinkCop")
class ClearMessages(commands.Cog):
def __init__(self, bot):
@@ -8,23 +11,19 @@ class ClearMessages(commands.Cog):
@commands.command()
async def clear(self, ctx, amount=0):
if amount == 0:
fail = await ctx.send("Please enter an amount to delete!")
await asyncio.sleep(6)
await fail.delete()
member = ctx.author.display_name
LOGGER.info(f"Clear {amount} messages requested by {member}")
authors = {}
if amount < 3:
await ctx.channel.purge(limit=amount)
sucess = await ctx.send(
f"{amount} messages has been deleted <a:Verified:878231325469974599>") # sending success msg
await asyncio.sleep(6) # wait 6 seconds
await sucess.delete() # deleting the success msg
async for message in ctx.channel.history(limit=amount + 1):
if message.author not in authors:
authors[message.author] = 1
else:
authors[message.author] += 1
await message.delete()
else:
if amount == 0:
fail = await ctx.send("Please enter an amount to delete!")
await asyncio.sleep(6)
await fail.delete()
msg = "\n".join([f"{author}:{amount}" for author, amount in authors.items()])
await ctx.channel.send(msg)
def setup(bot: commands.Bot):