【问题标题】:Python 3 - Discord BotPython 3 - 不和谐机器人
【发布时间】:2017-12-29 04:56:32
【问题描述】:

我正在制作一个不和谐的机器人,我希望它清除服务器中的消息。我有代码,但是当我运行它时,它会询问我的权限。如何授予机器人删除频道消息的权限?

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    您的机器人用户帐户需要在您运行命令的特定服务器/公会上具有MANAGE_MESSAGES permission 才能删除消息。这需要由服务器管理员在安装您的机器人时进行设置(通常,它是通过机器人使用的自定义角色完成的)。您可以检查以确保您具有以下角色:

    # get your bot's guild member object first (that's outside the scope of this post)
    # we'll call the guild member object "member" here...
    
    # MANAGE_MESSAGES permission is 0x00002000, we'll use a bitwise AND to see if the
    # bot has a role with the MANAGE_MESSAGES permission.
    if not filter(lambda role: role.permissions & 0x00002000 != 0, member.roles):
        # error handling, possibly send a message saying the bot needs permissions
    else:
        # delete messages using your method
    

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 2021-05-27
      • 2021-07-15
      • 2021-03-29
      • 2021-07-11
      • 2021-03-25
      • 2018-08-13
      • 2021-02-28
      • 2021-07-13
      相关资源
      最近更新 更多