discord - 如何将用户对象转换为名称
问题描述
目前用户的输出是Team_<@378014902620520451>
. 如何将其转换为播放器的用户名?
team_one_capatain = []
team_two_capatain = []
team_one_capatain.append(random.choice(queue))
team_two_capatain.append(random.choice(queue))
for captain_one in team_one_capatain:
for captain_two in team_two_capatain:
""" queue.remove(team_one_capatain)
queue.remove(team_two_capatain) """
embed = discord.Embed(color=discord.Color.teal())
embed.add_field(name=f'Team_{captain_one}', value=None, inline=True)
embed.add_field(name='PLAYERS', value=',\n'.join(queue), inline=True)
embed.add_field(name=f'Team_{captain_two}', value=None, inline=True)
embed_message = await ready_channel.send(embed=embed)
for i in range(0, len(queue)):
await embed_message.add_reaction(emoji_numbers[i])
解决方案
如果captain_one
是discord.User
or类型discord.Member
,则可以使用captain_one.display_name
. 该文档解释了该display_name
属性:
对于普通用户,这只是他们的用户名,但如果他们有公会特定的昵称,则返回该昵称。
(来源)
您可能感兴趣的其他属性:
- discord.User.name(与 discord.Member 相同)
- discord.User.discriminator(discord.Member 相同)
- discord.会员.nick
推荐阅读
- python - 如何在 python 中创建 4 维图?
- oracle - 在 WHERE 子句之后使用 IN 外部 CASE 语句我得到 SQL 错误 [1427] [21000]: ORA-01427: 单行子查询返回多于一行
- mstest - 哪个 TargetFrameworks 用于 mstest 单元测试项目来测试 .NET Standard 和多目标库?
- jfreechart - JfreeChart 时序图以小时和秒为单位呈现
- html - 增加 HTML 中图标的大小
- javascript - 如何仅使用 javascript 验证带有数字的输入字段?
- javascript - Nodemailer SES TRANSPORT 错误:TypeError:this.ses.sendRawEmail 不是函数
- mysql - 如何使用 SQL 从多个表中获取唯一列?
- mysql - SQL 为产品变体添加附加 ID
- scala - 如何在测试期间向 ZIO 提供自定义标头