【问题标题】:How can I make some commands only work if you have a specific permission with python?如果您对 python 有特定权限,我怎样才能使某些命令起作用?
【发布时间】:2022-01-26 18:58:52
【问题描述】:

我有一个命令“$clear”可以清除特定数量的消息。如果您只有“管理员”权限,我不知道如何使此命令起作用。如果有人知道如何做到这一点,这将对我有很大帮助,这是我的代码:

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

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    使用@commands.has_permissions(administrator=True) 装饰器将只允许管理员运行给定的命令。

    【讨论】:

    • 谢谢你,Broken Benchmark!为了澄清起见,我会将@client.command() 替换为@commands.has_permissions(administrator=True)?
    • 你会有两个装饰器。
    猜你喜欢
    • 2015-05-14
    • 2015-04-02
    • 2013-07-21
    • 1970-01-01
    • 2023-04-04
    • 2018-02-20
    • 2011-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多