【问题标题】:discord.py how would I put if user has admin permissions in a if statement?discord.py 如果用户在 if 语句中具有管理员权限,我将如何输入?
【发布时间】:2020-03-25 20:06:32
【问题描述】:

在一个完美的世界里,我想这样做:

if user who sent message has admin rights:

    answer()

但由于这不是一个完美的世界,我正在做的事情更像这样:

if message.content.startswith('hello'):
        if (somthng to detect if admin)
            print('hello')

我错过了那一行,然后我会很高兴,但我找不到任何东西。当我上网时,它说要使用这样的东西:

@bot.command()
@has_permissions(admin=True)  
async def stock(self, ctx, Member: discord.Member):
          print (hello)

但是我太笨了,无法理解任何不是 if 语句的东西

你能帮我解决这个问题吗?

【问题讨论】:

    标签: python-3.x discord.py


    【解决方案1】:

    如果您在服务器中收到消息,message.author 对象将属于 member 类。 member 类的属性为 member.guild_permissions documentation。

    这将返回一个permissions 对象。这是一个抽象类,可以找到here in the documentation。它有很多实用方法,你要找的是administratordocumentation。

    因此,您的 if 语句应如下所示:

    if message.author.guild_permissions.administrator:
         print('hello')
    

    【讨论】:

      猜你喜欢
      • 2021-05-23
      • 2021-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      • 2023-03-10
      相关资源
      最近更新 更多