python - 更新角色时不会调用 on_guild_role_update 函数

标签 python discord

我的机器人目前位于 3 个服务器中,并且函数 on_guild_role_update 不会在任何地方被调用,而且永远不会被调用。该机器人确实具有管理员权限,因此它应该可以看到所有受到限制的内容。我在 on_ready 函数之前有一个 @bot.event 装饰器,在其之后和 on_guild_role_update 之前有另一个装饰器。 它看起来像这样:

@bot.event
async def on_ready():
    #on_ready code

@bot.event
async def on_guild_role_update(before, after):
    print("1") #Included this just to see If the function even executes. It doesn't
    if before.name != after.name:
        embed = discord.Embed(title="Role " + before.name + " renamed to " + after.name + ".")
        embed.set_author(name="Role update")
        await bot.message.send(bot.get_channel(str(channelid)), embed=embed)

我错过了什么或者这不再起作用了吗?我已经检查了文档,但除了 this ,我没有找到任何相关内容。

最佳答案

您使用的是旧版本的discord.py。您可以通过运行获取最新的

python -m pip install -U discord.py

使用您运行机器人的Python解释器。 1.0 版本引入了几项重大更改,因此您必须使用 migration guide将您的代码更改为新接口(interface)。

关于python - 更新角色时不会调用 on_guild_role_update 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57598266/

相关文章:

python - 通过 node.js 运行 python 文件

c# - 为绕过 token 触发 hCaptcha 回调函数

python - 检查日期是否在世界某个地方有效

python - 如何绘制分类报告?

python - 为什么 numpy 的 asinh 输出因操作系统而异?

javascript - discord.js v13 permissions.has() 函数不工作(TypeError : Cannot read properties of undefined (reading 'has' ))

python - 我如何知道命令是否需要用户具有特定权限(才能运行)?

python - 将项目添加到链接列表的末尾会产生奇怪的结果

python - 不带换行符打印 (print 'a' ,) 打印一个空格,如何删除?

javascript - 警告 : Property commands is not defined in type module :"discord.js". 客户端