0

right now I am struggling to find a way to set a minimum amount of messages that can be purged. Basically I want it so whenever someone uses the command it will send an error for typing 0 or nothing for amount. I tried some things but they did not seem to work so I guess someone in here will know how to help me.

The code is this:

    @commands.command()
    @commands.has_permissions(manage_messages=True)
    async def clear(self, ctx, *, limit=None):

        await ctx.message.delete()

        channel = ctx.channel
        messages = await channel.history(limit=123).flatten()

        if limit != 0 or None:
            if not messages:
                await ctx.channel.send("I am really sorry but I can not purge an empty channel!")
                return
            else:
                try:
                    await channel.purge(limit = limit)
                    return
                except discord.Forbidden:
                    return await ctx.channel.send('I do not have perms')
        else:
            ctx.channel.send('Minimum amount of purge is 1!')
            return

In the beginning I had the limit=None to limit=100 and the None in the if limit != 0 or None was not working. Now I changed it but whenever I put any number that has nothing to do with 0 or None it does not work. Any ideas why and how to fix it?

xXSkillexZ
  • 105
  • 1
  • 12
  • Does this answer your question? [How to test multiple variables against a value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value) – Nurqm Feb 15 '21 at 20:10

1 Answers1

0

This line if limit != 0 or None: has to be if limit != 0 or limit == None:. For each comparison you need to declare what it's comparing to.

Additionally, to check if it's over a certain limit, you can just use a less-than symbol comparison. E.g. if limit < 5: return

Kelo
  • 1,783
  • 2
  • 9
  • 21
  • I tried this, but it did not work, I gave up because it was just too much I guess. The bot will be fine without this feature I guess. Thanks tho! – xXSkillexZ Feb 16 '21 at 19:04