【问题标题】:How to change someone's nickname when a user joins the server || Discord.py用户加入服务器时如何更改某人的昵称 ||不和谐.py
【发布时间】:2021-08-01 23:31:50
【问题描述】:

当有人加入服务器时,我希望我的机器人在用户名中添加一个氏族标签,但我对如何做到这一点感到困惑。您的帮助将不胜感激

【问题讨论】:

  • 你尝试了什么?查看文档可以帮助您...
  • 此链接可能会有所帮助:documentation, StackOverflow
  • 只是一个建议 - 在用户加入时将用户添加到不和谐角色不是更好吗?这将使您可以使用它们做更多的事情。

标签: python discord discord.py


【解决方案1】:

机器人可以检测到新成员何时以on_member_join() event reference 加入公会。然后您可以使用Member.nick 获取成员的昵称,您可以使用Member.edit 更改成员的昵称,传递nick= 关键字参数。

CLAN_TAG = "TAG"

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

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

【讨论】:

  • 它没有用。用户的昵称就是这样。我打开了意图
【解决方案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")

【讨论】:

    猜你喜欢
    • 2021-03-10
    • 2021-03-26
    • 2023-04-07
    • 2021-05-14
    • 2022-11-22
    • 1970-01-01
    • 2021-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多