Reputation: 77
I have made a command that I want to be accessible to only admins. If the user has admin, a specific code runs. If not, I want the bot to send a message like "Sorry, you cannot use that". Is there a way to do this?
Upvotes: 0
Views: 56
Reputation: 1373
@commands.command()
@commands.has_permissions(administrator=True)
async def command(self, ctx):
#code here
Would make the command command
admin only.
As for warning the user for trying to run a command they don't have permission for, you can use an error handler / command specific error handler.
Such as
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if isinstance(error, commands.errors.MissingPermissions):
msg.title = "Missing Permission ⛔"
msg.description = error.args[0]
return await ctx.send(embed=msg)
For a cog specific error, use commandname.error() and catch the error like shown above.
Upvotes: 2