'How to change nickname (discord.py)

I want to make a command that changes a nickname to a specific user (Let it be Example # 1234). This command accepts an argument in which a new nickname must be entered, to which the old nickname must be changed - g!Chnick "ExampleNick". I do not know how to change the nickname to users of the Discord server, I tried it through the Guild class, I tried it through the Member class. (Sorry for bad english)



Solution 1:[1]

It's not hard! For example you can use:

@client.command(pass_context=True)
async def chnick(ctx, member: discord.Member, nick):
    await member.edit(nick=nick)
    await ctx.send(f'Nickname was changed for {member.mention} ')

Don't forget a important thing, bot MUST have a permission for changing nicknames and can't change server owner nickname. Test it on other bots or members of server

My advice for you is reading discord.py documentation.

Solution 2:[2]

See documentation there and change nickname via await member.edit(nick="New Nickname"). Or show your code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Clonexy
Solution 2 Mixno