how can i change a nickname of a user on discord.py

Viewed 271

i was trying to change nicknames on discord.py 1.7.3 but i'd tried some times in different ways but don't have success

import discord
from discord.ext import commands
import urllib.request
import json
import datetime as DT
import configparser
import os
from discord.utils import get

class Search(commands.Cog):

@commands.command()
async def search(self, ctx, option, *, name):
for member in ctx.guild.members:
              if(member.nick == name):
                await member.edit(nick="teste")

also, i tried start with:

@commands.command(pass_context=True)
    async def search(self, ctx, option, *, name, discMember: discord.Member):

and fail too, when i use "discMember: dscord.Member", the code stop running, don't know why doesn't work

2 Answers
@commands.command()
async def change_nick(self, ctx, member: discord.Member):
    await member.edit(nick="test")

The you can use this command by typing something like [your_prefix]change_nick @Member#1234 in a chat. Where [you_prefix] is you bot's prefix and @Member#1234 is a member mention.

ok, guys, i realized that bot need a higher role then the target who u want to update nickname.

so, nothing is wrong with the code.

Related