python - Discord.py 重写在 DM 中从用户消息中更改昵称
问题描述
所以,我正在尝试为我的机器人执行一个不和谐的命令。命令是每次用户进入服务器时,机器人都会向用户打招呼并询问其名称。然后用户回复一条包含其名称的消息,然后机器人将服务器中用户的昵称更改为第一个用户回复的昵称。所以fa我没有运气找到如何但是我制作了这个代码并发送dm并阅读回复,但它不会改变昵称,有什么帮助吗?
编辑:所以我听从了某人的建议,这就是编码所发生的事情
@client.event
async def on_member_join(member):
await member.send(f"""Welcome to the server {member.name}!""")
await member.send("Please enter your full name: ")
def check(m): #checks if message was sent by someone other than the bot
return m.author != client.user
name = await client.wait_for('message', check=check)
await name.author.edit(nick=name.content)
现在的问题是,每当我尝试用最后一行更改昵称时,都会弹出此错误:
Ignoring exception in on_member_join
Traceback (most recent call last):
File "/Users/bermed28/opt/anaconda3/envs/pyBot/lib/python3.6/site-packages/discord/client.py", line 303, in _run_event
await coro(*args, **kwargs)
File "/Users/bermed28/Desktop/pyBot/bot.py", line 56, in on_member_join
await name.author.edit(nick=name.content)
AttributeError: 'User' object has no attribute 'edit'
解决方案
找到了答案,我所要做的就是以下代码:
@client.event
async def on_member_join(member: discord.Member):
await member.send(f"""Welcome to the server {member.name}!""")
await member.send("Please enter your full name: ")
def check(m): # checks if message was sent by someone other than the bot
return m.author != client.user
name = await client.wait_for("message",check=check)
await member.edit(nick=str(name.content))
推荐阅读
- wicket - 带有自定义日期表的 Wicket AjaxCheckBox
- java - 尝试运行简单的动态脚手架 Grails 应用程序会导致 ORA-00904 错误
- python - 为什么 Keras 中的 Concatenate Layer 会让训练变得很慢?
- python - 如何从矩阵中每一行的向量化总和与另一个矩阵实现矩阵
- vba - 使用 INSERT 保存记录 - SAVE 和 1 INSERT 不起作用,但其余工作正常
- c# - 如何将假货注入 DI 容器?
- html - 使用 flexbox,在 flexitem 内的 div 上显示滚动条
- java - 如何在 TaskExecutionAutoConfiguration 旁边创建额外的 TaskExecutor?
- javascript - 使用 NodeJS 在 Firebase 数据库中创建 Schema
- javascript - “数字”类型的参数不可分配给“持续时间构造器”类型的参数