当用户的角色更新时,我希望机器人在 Admin 之后以他们的名字附加他们的用户名,例如.管理员 |用户名 但它不起作用.这是我的代码:
When a user's role gets updated, I would like the bot to append their username after Admin in their name Eg. Admin | username But it doesn't work. Here's my code:
@client.event
async def on_member_update(before, after):
role = discord.utils.get(before.guild.roles, name="Admin")
if after in role.members:
await after.edit(nick="Admin | " + discord.user, reason=None)
discord.user 是一个类,我们想要一个字符串,它是用户的昵称,user_name.
discord.user is a class, we want a string that is the nick, user_name of the user.
@client.event
async def on_member_update(before, after):
role = discord.utils.get(before.guild.roles, name="Admin")
if after.nick is not None and after.nick.startswith("Admin |"):
return
if after in role.members:
await after.edit(nick="Admin | " + after.display_name, reason=None) #discord.user is a class, we want the member's new display name.
这篇关于更改用户的昵称——Discord.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何制作一个在 Python 中提供角色的不和谐机器人How to make a discord bot that gives roles in Python?(如何制作一个在 Python 中提供角色的不和谐机器人?)
Discord 机器人没有响应命令Discord bot isn#39;t responding to commands(Discord 机器人没有响应命令)
你能得到“关于我"吗?Discord 机器人的功能?Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“关于我吗?Discord 机器人的功能?(不和谐.py))
message.channel.id Discord PYmessage.channel.id Discord PY(message.channel.id Discord PY)
如何在 heroku 上托管我的 discord.py 机器人?How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 机器人?)
discord.py - 自动更改角色颜色discord.py - Automaticaly Change an Role Color(discord.py - 自动更改角色颜色)