当用户加入服务器| | Discord.py时如何更改某人的昵称

2024-05-29 05:51:50 发布

您现在位置:Python中文网/ 问答频道 /正文

当有人加入服务器时,我想让我的机器人在用户名中添加一个氏族标记,但我不知道该怎么做。谢谢你的帮助


Tags: 标记机器人用户名服务器时氏族
2条回答

如果你用的是齿轮

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")

机器人可以检测到新成员何时加入带有^{} event reference的公会。然后,您可以使用^{}获取成员的昵称,您可以使用^{}更改成员的昵称,并传递nick=关键字参数

CLAN_TAG = "TAG"

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

如果成员的原始昵称是昵称,则他们的新昵称将是[TAG]昵称

相关问题 更多 >

    热门问题