简体   繁体   English

如果您拥有 python 的特定权限,我如何才能使某些命令有效?

[英]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.我有一个命令“$clear”,它清除特定数量的消息。 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.使用@commands.has_permissions(administrator=True)装饰器将只允许管理员运行给定的命令。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎样才能让我只能在我的 Discord 机器人上使用某些命令? (Python) - How can I make sue only I can use certain commands on my Discord bot? (Python) 在 discord.py 我怎样才能让我的机器人命令只能在特定通道或特定服务器中使用? - in discord.py How can i make my bot that the commands only can be use in specific channel or specific server? 如何启动python shell并使用某些命令自动初始化它? - How can I start the python shell and automatically initialize it with some commands? 如何在python 3中使浮点数具有特定范围(或者我完全可以)? - How can I make an float have a specific range in python 3 (or can I at all)? 如何使“has_object_permission()”工作? - How can I make "has_object_permission( )" work? massban / massunban 命令仅适用于服务器内的用户。 我怎样才能使它也禁止/取消禁止不在服务器中的用户? - massban / massunban commands only work for users within the server. How can I make it so it also bans/unbans users not in the server? 我如何还可以检查成员是否具有特定角色是 if 语句? 仅当您具有特定角色时才需要 elif 执行? - how can I also check if a member has a specific role is an if statement? need the elif to only execute if you have a specific role? 如何列出可调用命令 python? - how can I make a list of callable commands python? 是mod_WSGI取代了Apache在做什么以及我如何才能使WSGI仅在特定路径下工作 - Is mod_WSGI replacing what apache is doing and how I can make wsgi work at a specific path only Python 中是否有某种方法可以让特定的代码行继续到下一个? - Is there some way in Python where you can have a specific line of code continuing to the next?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM