首页 > 解决方案 > 昵称不是在不和谐中改变吗?

问题描述

@client.event
async def on_message(message):
    if message.author.nick == f"[AFK] {message.author.name}":
        print("AFK Guy detected")
        who = message.author
        await who.edit(nick=f"{message.author.name}")
        await message.channel.send(f"Hey, {message.author.mention} welcome back, I removed your AFK.")

    await client.process_commands(message)

当用户处于 AFK 状态并返回并发送消息时,它不会重新更改他的姓名或执行任何操作 为什么会这样?

标签: pythonpython-3.xdiscorddiscord.py

解决方案


我刚刚测试了它并且它有效!

@client.event
async def on_message(message):
    if message.author.nick.startswith("[AFK]"):
        print("AFK Guy detected")
        who = message.author
        await who.edit(nick=f"{message.author.name}")
        await message.channel.send(f"Hey, {message.author.mention} welcome back, I removed your AFK.")

    await client.process_commands(message)

可能是 和 之间的[AFK]空格{message.author.name}。我还添加了一个.startswith,它检查它是否以“[AFK]”开头。它只是好一点。


推荐阅读