P
P
Peachuser2021-03-14 17:28:55
Python
Peachuser, 2021-03-14 17:28:55

How to set a limit for the bot to delete messages with the /clear command, 100 messages maximum?

Good afternoon, I want to make a restriction on deleting messages to the bot, how can I implement this?
Here is the code

@client.command(pass_context = True)
@commands.has_any_role(819292703589269514,817408828500213860,817408830240456754,817643991331766283)
async def clear (ctx, amount : int):
    await ctx.channel.purge(limit = amount + 1)
    emb = discord.Embed (title = 'Удалено {} сообщений!'.format(amount), colour = discord.Color.gold())
    await ctx.send(embed = emb, delete_after=30)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2021-03-14
@fixator10

Add a check on the value of the amount variable?

if amount > 100:
    await ctx.send("Too many messages, aborting...")
    return

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question