昵称不会乱改?

时间:2021-07-13 22:05:35

标签: python python-3.x discord discord.py

@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 状态并返回并发送消息时,它不会更改他的姓名或执行任何操作 这是为什么?

1 个答案:

答案 0 :(得分:0)

我刚刚对其进行了测试,效果很好!

@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]”开头。稍微好一点。