import logging from discord.ext import commands import asyncio LOGGER = logging.getLogger("Discord_Radio_Bot.LinkCop") class ClearMessages(commands.Cog): def __init__(self, bot): self.Bot = bot @commands.command() async def clear(self, ctx, amount=0): member = ctx.author.display_name LOGGER.info(f"Clear {amount} messages requested by {member}") authors = {} 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() msg = "\n".join([f"{author}:{amount}" for author, amount in authors.items()]) await ctx.channel.send(msg) def setup(bot: commands.Bot): bot.add_cog(ClearMessages(bot))