Discord.py on_member_update 不起作用,启用了成员意图

时间:2021-06-04 22:56:11

标签: python discord.py

我使用 on_member_update 事件编码了这个东西,这样我的机器人就会在我的服务器中踢出一个没有角色并离线的成员,以及对他们进行 DM。当我执行此代码时,它什么也不做,甚至不会引发错误。

@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))

0 个答案:

没有答案