Skip to content

Instantly share code, notes, and snippets.

@8dcc
Created September 9, 2021 20:42
Show Gist options
  • Save 8dcc/c684325e461d70c06b76277aedfe08d8 to your computer and use it in GitHub Desktop.
Save 8dcc/c684325e461d70c06b76277aedfe08d8 to your computer and use it in GitHub Desktop.
Discord bot purge 2
# 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):
def check_purge(check_me):
return check_me.author.id == member.id
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
deleted = await ctx.channel.purge(limit=amount, check=check_purge)
embed = discord.Embed(title="Channel purged", description="**%s** removed %s messages by **%s**" % (ctx.author.display_name, len(deleted), member.display_name), color=0xff1111)
await ctx.send(embed=embed)
debug_print('[Bot] User %s requested purge. Deletd %s messages from user: %s' % (ctx.author, len(deleted), member))
@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