Python 3 - Discord 机器人

标签 python discord.py

我正在制作一个不和谐的机器人,我希望它能够清除服务器中的消息。我有代码,但是当我运行它时,它要求我提供权限。如何授予机器人删除 channel 消息的权限?

最佳答案

您的机器人用户帐户需要具有 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

关于Python 3 - Discord 机器人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44104189/

相关文章:

python - Pyspark- case 语句中的子查询

Python tweepy 查找荷兰的所有推文

python - __reduce__ 函数在 pickle 模块的情况下如何工作?

python - 列出没有共同公会的 friend ,discord.py 重写

python - 检查 Discord 机器人是否在线

python - 使用 Python 编程 Discord 机器人 - 如何使机器人将命令限制到特定服务器?

python - Discord.py 和 youtube_dl、 "Read error"和 "The session has been invalidated for some reason"

python - Django 帮助 : AttributeError: 'module' object has no attribute 'Charfield'

python - Plotly:如何将分类变量插入平行坐标图中?

python - 如何为不和谐用户重置命令冷却时间?