【问题标题】:Nickname isn't changing in discord?昵称不是在不和谐中改变吗?
【发布时间】:2021-07-13 22:05:35
【问题描述】:
@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 并返回并发送消息时,它不会重新更改他的名字或做任何事情 这是为什么呢?

【问题讨论】:

  • 是否曾经在控制台打印过“AFK Guy Detected”?
  • 它永远不会打印

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


【解决方案1】:

我刚刚测试过,它有效!

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

【讨论】:

  • 对不起,我的代码还没有完成。网站崩溃了。还要确保安装了最新的 discord.py
  • 我有最新的 discord.py
  • 仍然没有打印任何东西
  • 嗯,这很奇怪。你能在命令提示符下pip show discord 告诉我版本吗?
  • 版本为1.7.3
猜你喜欢
  • 2021-03-10
  • 2021-04-05
  • 1970-01-01
  • 2021-05-14
  • 1970-01-01
  • 2021-05-25
  • 1970-01-01
  • 2021-03-20
  • 2021-12-27
相关资源
最近更新 更多