Clear Messages Changes
- Better logging
- Better output
This commit is contained in:
Logan Cusano
2022-04-09 21:58:34 -04:00
parent 35e19ee83f
commit 8d090c5c67

View File

@@ -1,6 +1,5 @@
import logging
from discord.ext import commands
import asyncio
LOGGER = logging.getLogger("Discord_Radio_Bot.LinkCop")
@@ -12,17 +11,24 @@ class ClearMessages(commands.Cog):
@commands.command()
async def clear(self, ctx, amount=0):
member = ctx.author.display_name
mtn_member = f"<@{member}>"
LOGGER.info(f"Clear {amount} messages requested by {member}")
authors = {}
async for message in ctx.channel.history(limit=amount + 1):
authors = {}
async for message in ctx.channel.history(limit=amount):
if message.author not in authors:
authors[message.author] = 1
else:
authors[message.author] += 1
await message.delete()
msg = "\n".join([f"{author}:{amount}" for author, amount in authors.items()])
msg = f"{mtn_member}, I deleted {sum(authors.values())} messages\n"
LOGGER.debug(f"Deleted {sum(authors.values())} messages from {ctx.message.channel}")
for author in authors.keys():
msg += f"\t{author}: {authors[author]}"
LOGGER.debug(f"Deleted {authors[author]} messages from {author}")
await ctx.channel.send(msg)