IDK
IDK

Reputation: 131

How to change someone's nickname when a user joins the server || Discord.py

I want my bot to add a Clan Tag in the user's name when someone joins the server but I am confused about how to do it. Your help would be appreciated

Upvotes: 0

Views: 995

Answers (2)

shiüo
shiüo

Reputation: 36

If you're using cogs,

import discord
from discord.ext import commands
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=config.prefix,intents = intents)
# You can find Intents in Bot entries on the discord developer site.

------------------------------------------------------------------------------------
# change someone's nickname when a user joins the server

@commands.Cog.listener()
async def on_member_join(self, member):
    await member.edit(nick="nickname here")

Upvotes: 2

Jacob Lee
Jacob Lee

Reputation: 4680

The bot can detect when a new member joins the guild with the on_member_join() event reference. You can then get the member's nickname with Member.nick and you can change the member's nickname with Member.edit, passing the nick= keyword argument.

CLAN_TAG = "TAG"

@bot.event
async def on_member_join(member):
    await member.edit(nick=f"[{CLAN_TAG}]{member.nick}")

If the member's original nickname was Nickname, their new nickname would be [TAG]Nickname.

Upvotes: 0

Related Questions