Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python3-Discord机器人_Python_Discord.py - Fatal编程技术网

Python3-Discord机器人

Python3-Discord机器人,python,discord.py,Python,Discord.py,我正在制作一个discord bot,我希望它能够清除服务器中的消息。我有代码,但当我运行它时,它会向我请求权限。如何授予bot删除频道消息的权限 您的bot用户帐户需要在您运行命令的特定服务器/公会上具有管理_消息,才能删除消息。这需要由服务器管理器在安装bot时进行设置(通常,这是通过bot使用的自定义角色完成的)。您可以按如下方式进行检查以确保您具有该角色: # get your bot's guild member object first (that's outside the sco

我正在制作一个discord bot,我希望它能够清除服务器中的消息。我有代码,但当我运行它时,它会向我请求权限。如何授予bot删除频道消息的权限

您的bot用户帐户需要在您运行命令的特定服务器/公会上具有
管理_消息
,才能删除消息。这需要由服务器管理器在安装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