From be767478f44f0a4d49d0baa70435d9968ec5116e Mon Sep 17 00:00:00 2001 From: Michael H Date: Fri, 4 May 2018 00:15:27 -0400 Subject: [PATCH] allow deletion based on user ID (actually this time) (#1561) --- redbot/cogs/cleanup/cleanup.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/redbot/cogs/cleanup/cleanup.py b/redbot/cogs/cleanup/cleanup.py index 869c27955..80e5082a7 100644 --- a/redbot/cogs/cleanup/cleanup.py +++ b/redbot/cogs/cleanup/cleanup.py @@ -124,26 +124,34 @@ class Cleanup: @cleanup.command() @commands.guild_only() @commands.bot_has_permissions(manage_messages=True) - async def user(self, ctx: RedContext, user: discord.Member or int, number: int): + async def user(self, ctx: RedContext, user: str, number: int): """Deletes last X messages from specified user. Examples: cleanup user @\u200bTwentysix 2 cleanup user Red 6""" + try: + member = await commands.converter.MemberConverter().convert(ctx, user) + except commands.BadArgument: + try: + _id = int(user) + except ValueError: + raise commands.BadArgument() + else: + _id = member.id + channel = ctx.channel author = ctx.author is_bot = self.bot.user.bot - + if number > 100: cont = await self.check_100_plus(ctx, number) if not cont: return def check(m): - if isinstance(user, discord.Member) and m.author == user: - return True - elif m.author.id == user: # Allow finding messages based on an ID + if m.author.id == _id: return True elif m == ctx.message: return True @@ -156,7 +164,7 @@ class Cleanup: reason = "{}({}) deleted {} messages "\ " made by {}({}) in channel {}."\ "".format(author.name, author.id, len(to_delete), - user.name, user.id, channel.name) + member or '???', _id, channel.name) log.info(reason) if is_bot: