python - Discord.py on_member_update 不起作用,启用了成员意图
问题描述
我有这个我使用 on_member_update 事件编码的东西,这样我的机器人就会踢出我的服务器中没有角色并离线的成员,以及对他们进行 DMing。当我执行此代码时,它什么也不做,甚至不会引发错误。
@bot.event
async def on_member_update(before, after):
if before.status != after.status:
if len(after.roles) == 0:
if str(after.status) == "offline":
reason = "Went offline without verifying"
dmkickembed = discord.Embed(title = "Reason: " + reason, description = "_ _", color = 0x2F3136)
dmkickembed.set_author(name = f"You have been kicked from server.", icon_url = f"{bot.user.avatar_url}")
dmkickembed.add_field(name = "Come back with this link:", value = "link")
try:
# send to member
await after.send(embed = dmkickembed)
except discord.HTTPException:
pass
# kick here
await after.kick(reason=reason)
我什至尝试在事件打印 str(after.status) 中使用第一行。仍然绝对什么都不做。正如您所知,是的,我在代码和 Discord Dev Portal 中都启用了成员意图。
这是我启用意图的方式:
intents = discord.Intents.default()
intents.members = True
intents.presences = True
bot = commands.Bot(command_prefix=["m/", "M/"], status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.playing, name="Loading...", intents=intents))
解决方案
推荐阅读
- java - 如何从显示的活动中设置片段文本视图
- php - PHP:如何替换数组中的最后 X 个元素
- reactjs - React Hooks-useEffect 和 onClick 问题
- jsonschema - JSON模式在运行时根据列表验证输入
- javascript - 如何在 Vue 3 中使用 laravel-vue-pagination?
- python - 导入 PySide2 时出现 ImportError
- r - 在关键字之间提取R中的文本
- javascript - 如何在我的网页中添加访客计数器?
- performance - Flutter 小部件不返回值并聚焦下一个/上一个元素
- reactjs - 缓存匹配在反应中返回未定义