Clear Messages Changes
- Check for negative numbers... Gino
This commit is contained in:
Logan Cusano
2022-04-09 22:14:21 -04:00
parent dcf0de8351
commit 9dba89a60b

View File

@@ -14,29 +14,33 @@ class ClearMessages(commands.Cog):
"\t@ clear\n"
"\t@ clear 10",
breif="Clear x messages in the channel it's called in")
async def clear(self, ctx, amount=2):
async def clear(self, ctx, amount: int = 2):
member = ctx.author.display_name
member_id = ctx.author.id
mtn_member = f"<@{member_id}>"
LOGGER.info(f"Clear {amount} messages requested by {member}")
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()
if amount < 0:
ctx.send(f"{member}, the number needs to be positive...")
msg = f"{mtn_member}, I deleted {sum(authors.values())} messages from {len(authors.keys())} users:\n"
LOGGER.debug(f"Deleted {sum(authors.values())} messages from {ctx.message.channel}")
else:
LOGGER.info(f"Clear {amount} messages requested by {member}")
for author in authors.keys():
msg += f"\t{str(author).split('#', 1)[0]}: {authors[author]}\n"
LOGGER.debug(f"Deleted {authors[author]} messages from {author}")
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()
await ctx.channel.send(msg)
msg = f"{mtn_member}, I deleted {sum(authors.values())} messages from {len(authors.keys())} users:\n"
LOGGER.debug(f"Deleted {sum(authors.values())} messages from {ctx.message.channel}")
for author in authors.keys():
msg += f"\t{str(author).split('#', 1)[0]}: {authors[author]}\n"
LOGGER.debug(f"Deleted {authors[author]} messages from {author}")
await ctx.send(msg)
def setup(bot: commands.Bot):