mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 19:28:54 -05:00
allow deletion based on user ID (actually this time) (#1561)
This commit is contained in:
parent
b3ad5d90ed
commit
be767478f4
@ -124,26 +124,34 @@ class Cleanup:
|
|||||||
@cleanup.command()
|
@cleanup.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@commands.bot_has_permissions(manage_messages=True)
|
@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.
|
"""Deletes last X messages from specified user.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
cleanup user @\u200bTwentysix 2
|
cleanup user @\u200bTwentysix 2
|
||||||
cleanup user Red 6"""
|
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
|
channel = ctx.channel
|
||||||
author = ctx.author
|
author = ctx.author
|
||||||
is_bot = self.bot.user.bot
|
is_bot = self.bot.user.bot
|
||||||
|
|
||||||
if number > 100:
|
if number > 100:
|
||||||
cont = await self.check_100_plus(ctx, number)
|
cont = await self.check_100_plus(ctx, number)
|
||||||
if not cont:
|
if not cont:
|
||||||
return
|
return
|
||||||
|
|
||||||
def check(m):
|
def check(m):
|
||||||
if isinstance(user, discord.Member) and m.author == user:
|
if m.author.id == _id:
|
||||||
return True
|
|
||||||
elif m.author.id == user: # Allow finding messages based on an ID
|
|
||||||
return True
|
return True
|
||||||
elif m == ctx.message:
|
elif m == ctx.message:
|
||||||
return True
|
return True
|
||||||
@ -156,7 +164,7 @@ class Cleanup:
|
|||||||
reason = "{}({}) deleted {} messages "\
|
reason = "{}({}) deleted {} messages "\
|
||||||
" made by {}({}) in channel {}."\
|
" made by {}({}) in channel {}."\
|
||||||
"".format(author.name, author.id, len(to_delete),
|
"".format(author.name, author.id, len(to_delete),
|
||||||
user.name, user.id, channel.name)
|
member or '???', _id, channel.name)
|
||||||
log.info(reason)
|
log.info(reason)
|
||||||
|
|
||||||
if is_bot:
|
if is_bot:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user