【问题标题】:discord.py, on_member_update() not detecting status updates, but detects other eventsdiscord.py, on_member_update() 不检测状态更新,但检测到其他事件
【发布时间】:2022-01-07 02:09:18
【问题描述】:

我仍在学习 python/discord.py 并尝试构建一个简单的机器人来检测用户状态(在线/离线)的变化;下面显示的是一个应该检测所有成员更新的实现。

from discord.ext import commands
import discord

intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix="$", intents=intents)

target_channel_id = <id here>

@bot.event
async def on_ready():
    print("bot ready")

@bot.event
async def on_member_update(before, after):
    channel = bot.get_channel(target_channel_id)
    await channel.send("Member updated!")
    print("member updated!")

bot.run("<token here>")

机器人响应名称/角色更改证明了我的意图已正确启用,但状态更改似乎没有发生任何事情。就像我说的那样,我对 python 和 discord.py 仍然是新手,所以我不确定我是否只是不知道什么,但在文档中它说 on_member_update() 应该在状态更改时调用,所以我我不确定问题是什么。感谢您的阅读!

【问题讨论】:

  • 尝试打印before.statusafter.status并回复我
  • 当更改角色/名称时,它会按预期打印出状态,但是当更改状态时,什么都没有打印出来,这让我相信甚至没有在状态更改时调用该函数。
  • 你把我说的话打印出来了,只是告诉我观察

标签: python discord discord.py bots status


【解决方案1】:

在您的代码中启用以下三个意图,如果发生状态更新,您的代码将开始工作

intents = discord.Intents( guilds=True,members=True,presences=True)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-28
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多