0
votes

So, I'm trying to implement a command for my bot in discord. The command is that every time a user enters the server, the user is greeted by the bot and is asked for its name. The user then replies back with a message containing its name and then the bot changes the user's nickname in the server for the one th user replied with. So fa I've had no luck finding out how but I made this code and it sends the dm and reads the reply, but it doesn't change the nickname, any help?

EDIT: So I followed someone's advice and this is what happened up being coded

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

The problem now is that this whenever I try to change the nickname with the last line, this error pops up:

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
client.event does not work like that, consider using wait_for discordpy.readthedocs.io/en/latest/…chluebi
I just tried it, look at the edited post! Another error pops up!Fernando Bermúdez

1 Answers

1
votes

Found the answer, all I had to do was the following code:

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