Discord.py从DM中的用户消息重写更改昵称

时间:2020-06-08 02:45:51

标签: python discord.py discord.py-rewrite

因此,我正在尝试为我的机器人实施不一致的命令。该命令是,每当用户进入服务器时,机器人就会向该用户打招呼,并要求其输入名称。然后,用户用包含其名称的消息进行回复,然后,僵尸程序会在服务器中为第一个用户回复该用户的昵称。所以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'

1 个答案:

答案 0 :(得分:1)

找到答案了,我所要做的就是以下代码:

@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))