Answer the question
In order to leave comments, you need to log in
How to catch an error in slash commands in Python?
How to catch an error in slash commands?
The code:
@slash.slash(name="clear", description="Удалить сообщения", guild_ids=guild_ids,
options=[create_option(name="amount", description="Кол.во сообщений от 0 до 1000.", option_type=4, required=True)])
@client.command()
@commands.has_permissions(manage_messages=True)
@commands.bot_has_permissions(manage_messages=True)
async def clear(ctx, amount: int):
if amount < 0 or amount > 1000:
await ctx.reply("Неверно указано кол.во сообщений.\nмин **0** макс **1000**.")
else:
await ctx.channel.purge(limit=amount)
await ctx.send(f"Удалено **{amount}** сообщений.", delete_after=5)
@client.event
async def on_command_error(ctx, error):
if isinstance(error, MissingPermissions):
return await ctx.send("**У вас не достаточно прав!**")
if isinstance(error, BotMissingPermissions):
return await ctx.send("У меня нет прав на выполнения данной команды!\n**Нужные права:** \n > `Кикать пользователей`(для команды /kick), \n > `банить пользователей`(для команды /ban), \n > `удалять сообщения`(для команды /clear и защиты от спама)")
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question