Python 3不和谐B

2024-04-19 18:37:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做一个不和谐的机器人,我想让它清除服务器上的消息。我有代码,但当我运行它时,它会要求我提供权限。如何授予机器人删除频道消息的权限?在


Tags: 代码服务器消息权限机器人频道
1条回答
网友
1楼 · 发布于 2024-04-19 18:37:43

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

# 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

相关问题 更多 >