Python Discord.py重写在DM中更改用户消息的昵称
所以,我正试图在discord中为我的机器人实现一个命令。命令是,每当用户进入服务器时,bot就会向用户打招呼并询问其名称。然后用户回复一条包含其名称的消息,然后bot在服务器中为第1个用户更改用户的昵称。所以fa我一直没有找到答案,但是我做了这个代码,它发送dm并读取回复,但是它没有改变昵称,有什么帮助吗 编辑:所以我听从了别人的建议,这就是编码时发生的事情Python Discord.py重写在DM中更改用户消息的昵称,python,discord.py,discord.py-rewrite,Python,Discord.py,Discord.py Rewrite,所以,我正试图在discord中为我的机器人实现一个命令。命令是,每当用户进入服务器时,bot就会向用户打招呼并询问其名称。然后用户回复一条包含其名称的消息,然后bot在服务器中为第1个用户更改用户的昵称。所以fa我一直没有找到答案,但是我做了这个代码,它发送dm并读取回复,但是它没有改变昵称,有什么帮助吗 编辑:所以我听从了别人的建议,这就是编码时发生的事情 @client.event async def on_member_join(member): await membe
@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))
<代码>客户机。事件< /代码>不起作用,考虑使用<代码> WaITy < < /Cord> >我刚刚尝试过,查看编辑后的帖子!另一个错误弹出!