I made a clear slash command but the bot don’t verify the permissions of the interaction.user.
I tried with that @commands.has_permissions(administrator=True)
but It’s not working since it was working with a classic prefix command.
Also, I made error messages;
@bot.event
async def on_command_error(interaction, error):
if isinstance(error, commands.MemberNotFound):
- await interaction.send("Unknown Member!")
if isinstance(error, commands.MissingPermissions):
await interaction.send("You do not have right permissions !", delete_after = 3)
And here is my clear
command code:
@bot.tree.command(guild=discord.Object(id=1264715762199691446), name="clear", description="Supprimer un certain nombre de messages.")
@commands.has_permissions(manage_messages = True)
@app_commands.describe(nombre="Le nombre de messages à supprimer.")
async def clear(interaction: discord.Interaction, nombre : int):
messages = [message async for message in interaction.channel.history(limit = nombre)]
for message in messages:
await message.delete()
return await interaction.response.send_message(f"**<:trash:1264750959372927057> __{nombre}__ message(s) supprimé(s).**", delete_after=3)
I actually want that my bot detect a missing permission with Slash Commands and throw an error message to the user like seen above.
Also, as the member don’t have right permissions, I want the bot to return nothing.
Thank you.(Also im French so if you see some French line into strings thats normal)
Ruka Off is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.