简体   繁体   中英

How can I make some commands only work if you have a specific permission with python?

I have a command "$clear" which clears a specific number of messages. I do not know how to make this command work if you only have the permission "administrator". If anyone knows how to do this that would help me a lot, and here's my code:

async def clear(message, limit:int):
    await message.channel.purge(limit=limit)
    await message.channel.send(f'{limit} messages have been cleared.')

Using the @commands.has_permissions(administrator=True) decorator will only allow administrators to run the given command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM