我对 discord.py 包的 on_member_update 函数有疑问。
我的问题是 on_member_update 函数仅在机器人本身更新时触发(如角色更新),而不是在其他用户更新时触发(它应该如何工作)。
这是我的代码的细分:
import discord
from discord.ext import commands
import sys
TOKEN = 'myToken'
BOT_PREFIX = '!'
Intents = discord.Intents()
Intents.members = True
Intents.presences = True
bot = commands.Bot(command_prefix=BOT_PREFIX, Intents = Intents)
@bot.event
async def on_ready():
print("Logged in as: " + bot.user.name + "\n")
@bot.event
async def on_member_update(before, after):
if str(before.status) == "online":
if str(after.status) == "offline":
print("{} has gone {}.".format(after.name,after.status))
else:
print("lol")
@bot.command(pass_context=True)
async def stop(ctx):
await ctx.author.send("bot stopped")
sys.exit(0)
bot.run(TOKEN)
希望您知道如何使其发挥作用。
感谢您的帮助!
您应该从开发人员门户为您的机器人启用状态意图,如下图所示。
Discord 开发者门户 https://discord.com/developers/applications/
https://i.stack.imgur.com/cAn8m.png https://i.stack.imgur.com/cAn8m.png
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)