How to change the author's nickname on Discord.py

I was trying to make a register command. When a new user just came into the guild they land on our registering channel. I want them to use the command like this:

User: $changenick John Doe

Bot: Your new nickname is @John D.

I came up with something like this in my first attempt with some research on StackOverflow:

@Bot.command(pass_context=True) 
async def changenick(ctx, member: discord.Member, newnick, newnickSurname): 
    modRole = discord.utils.get(member.guild.roles, name='mod')
    await member.edit(nick=f"{newnick[0].upper()}{newnick[1:]} {newnickSurname[0].upper()}.")
    await ctx.send(f"Your new nickname is {member.mention}! {modRole.mention}s check if it's legit")

I realized you can change other users' nicknames with this code and added if(member == ctx.author) on top of the block. After this, I found out there can be people with multiple names. I didn't want to tag the users themselves every time so I relocated the member object and added an args variable in the arguments.

@Bot.command(pass_context=True) 
async def changenick(ctx, *names):  
    member=ctx.author   
    modRole = discord.utils.get(member.guild.roles, name='mod')
    await member.edit(nick=f"{names[0][0].upper()}{names[0][1:]} {names[-1][0].upper()}.")
    await ctx.send(f"Your new nickname is {member.mention}! {modRole.mention}s check if it's legit")

I feel like there's still room for more. Can I improve this further or is this enough?


Solution 1:

you can simply do this:

@bot.command()
async def nick(ctx,*, nick):
    await ctx.author.edit(nick=nick)
    embed = nextcord.Embed(title=f"You've been nicked for {nick}", color=0x000eff)
    await ctx.send(embed=embed)