BlackHummingbird
BlackHummingbird

Reputation: 21

DiscordPy Set Bot Nickname

I have been trying to get this to work for about an hour now, but my dumb brain cannot figure it out. basically i want to get my bot to set it's own nickname when someone says (prefix)name (namechangeto)

@client.command(aliases=["nick", "name"])

async def nickname(ctx, name="Bot"):

user = guild.me()

await user.edit(nick=name)

any help appreciated

(also sorry for bad formatting, and i know this code probably makes some people cringe lol im sorry)

Upvotes: 1

Views: 252

Answers (1)

Baptiste
Baptiste

Reputation: 306

For me the problem in your code is that your variable guild is not defined, so you have to use ctx.guild to get the good guild. Besides that, discord.Guild.me is not a function (callable with ()) but an attribute, you just have to use guild.me.

So you can try to make :

user = ctx.guild.me
await user.edit(nick=name)

In addition to that, it's not really the problem but an advice, you can use async def nickname(ctx, *, name="Bot"): instead of async def nickname(ctx, name="Bot"): to allow user to set a nickname with spaces in it.

So your final code for me is that :

@client.command(aliases=["nick", "name"])
async def nickname(ctx, *, name="Bot"):
    user = ctx.guild.me
    await user.edit(nick=name)

Have a nice day!

Baptiste

Upvotes: 2

Related Questions