python - 昵称不是在不和谐中改变吗?
问题描述
@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 状态并返回并发送消息时,它不会重新更改他的姓名或执行任何操作 为什么会这样?
解决方案
我刚刚测试了它并且它有效!
@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]”开头。它只是好一点。
推荐阅读
- java - Hibernate 不保存 ElementCollections
- python-3.x - 在 Ordinal Encoder 中指定编码顺序
- c - 如何从麦克风读取原始信号?
- javascript - 使用 url 源自动完成输入
- gradle - 通过 Gradle 为 IntelliJ 插件添加源
- java - 即使明确提供了模块路径,Eclipse 也找不到模块
- javascript - 获取当前工作目录名称而不是 Node.js 中的路径
- javascript - 根据多个选择输入返回不同的内容
- php - PHP 警告:SimpleXMLElement::__construct(): Entity: line 2: parser error : AttValue: " or ' 预期在
- scheme - Scheme中的科学记数法