Created
September 9, 2021 20:31
-
-
Save 8dcc/a21360c3f92266c0b03db7cc9b73e7ff to your computer and use it in GitHub Desktop.
Discord bot purge 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/r4v10l1/discord-bot | |
#---------------------------------------------------------------- | |
# Purge commands | |
@client.command(aliases=["clean"]) | |
@commands.check_any(commands.is_owner(), check_waifu(), check_server_owner()) | |
async def purge(ctx, member : discord.Member, amount : int): | |
if amount <= 0: | |
await ctx.send(':warning: **Missing required arguments. Usage:** `n!purge <username> <message_amount>`') | |
debug_print('[Bot] Could not parse negative integer for user: %s' % ctx.author) | |
return | |
remaining_messages = amount | |
messages = await ctx.channel.history(limit=99).flatten() | |
for message in messages: | |
if int(message.author.id) == int(member.id): | |
await message.delete() | |
remaining_messages -= 1 | |
if remaining_messages == 0: | |
break | |
embed = discord.Embed(title="Channel purged", description="**%s** removed %s messages by **%s**" % (ctx.author.display_name, amount, member.display_name), color=0xff1111) | |
await ctx.send(embed=embed) | |
@purge.error | |
async def purge_error(ctx, error): | |
if isinstance(error, commands.MissingRequiredArgument): | |
await ctx.send(':warning: **Missing required arguments. Usage:** `n!purge <username> <message_amount>`') | |
debug_print('[Bot] Could not parse arguments for user: %s' % ctx.author) | |
elif isinstance(error, commands.MemberNotFound): | |
await ctx.send(':warning: **Member not found. Make sure you don\'t use nicknames.**') | |
debug_print('[Bot] Could not parse arguments for user: %s' % ctx.author) | |
elif isinstance(error, commands.CheckFailure): | |
await ctx.send(':warning: **You don\'t have the permissions to do that, %s.**' % ctx.author.mention) | |
debug_print('[Bot] Could not parse arguments for user: %s' % ctx.author) | |
else: | |
print("--------------------------------\n%s\n----------------------------------" % error) | |
#---------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment