【发布时间】: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.status和after.status并回复我 -
当更改角色/名称时,它会按预期打印出状态,但是当更改状态时,什么都没有打印出来,这让我相信甚至没有在状态更改时调用该函数。
-
你把我说的话打印出来了,只是告诉我观察
标签: python discord discord.py bots status