首页 > 解决方案 > 如何将用户对象转换为名称

问题描述

目前用户的输出是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])

标签: discorddiscord.py

解决方案


如果captain_onediscord.Useror类型discord.Member,则可以使用captain_one.display_name. 该文档解释了该display_name属性:

对于普通用户,这只是他们的用户名,但如果他们有公会特定的昵称,则返回该昵称。

来源

您可能感兴趣的其他属性:


推荐阅读