首页 > 解决方案 > 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))

标签: pythondiscord.py

解决方案


推荐阅读