How to modify bot display name in discord.py

I’m working on a Discord bot and need help with updating its display name. I want to show live data like cryptocurrency prices in the bot’s display name that updates every few seconds.

I tried using this approach:

await client.user.edit(username=current_price)

But this changes the actual username permanently and Discord doesn’t allow frequent username changes.

Here’s my current code:

async def price_updater():
    while True:
        current_price = str(fetch_ETH_value(connection))
        await client.user.edit(username=current_price)
        await asyncio.sleep(3)

@client.event
async def on_ready():
    client.loop.create_task(price_updater())

What’s the correct way to change just the nickname instead of the username? I need something that can be updated frequently without hitting Discord’s rate limits.

The issue arises from using client.user.edit(), which alters the bot’s global username subject to strict rate limits. Instead, you should use guild.me.edit() to update the nickname specifically for each server.

For my price tracking bot, I implemented the following:

async def price_updater():
    while True:
        current_price = str(fetch_ETH_value(connection))
        for guild in client.guilds:
            try:
                await guild.me.edit(nick=f"ETH: ${current_price}")
            except discord.Forbidden:
                pass  # Handle lack of permission
        await asyncio.sleep(30)  # Rate limit consideration

It’s crucial to increase the sleep duration to 30 seconds. Frequent changes can still hit limits, and updating every few seconds isn’t necessary.

Been running a similar setup for months and learned this the hard way. Your main problem is trying to edit the global username which has extremely tight rate limits. You need to modify the nickname per server using the guild’s member object.

Here’s what worked for me:

async def price_updater():
    while True:
        current_price = str(fetch_ETH_value(connection))
        for guild in client.guilds:
            try:
                member = guild.get_member(client.user.id)
                if member:
                    await member.edit(nick=f"ETH ${current_price}")
            except discord.HTTPException:
                continue
        await asyncio.sleep(20)

The key difference is getting the member object first, then editing it. Also make sure your bot has manage nicknames permission in each server. I’ve found 20 seconds works well without hitting limits but you might need to adjust based on how many servers your bot’s in.

yeah, guild.me.edit() works but check your bot has ‘change nickname’ permission first. 30 sec is pretty conservative - I run 10-15 sec on my price bot without problems. Just handle exceptions proper or it’ll crash when it can’t update in some servers.