不和谐.py:如果成员没有特定角色,如何抵抗结果"None"



我正在设置"用户信息";我创建了2个字段,其中显示了我选择的一些字段中成员的最高角色,但当该用户没有任何角色时,命令(正确地(将不再执行。尽管它没有发挥作用,但我该如何完成它?我希望它能显示其他类型的";无";而不是角色。

@client.command(aliases=["UserInfo","User_info","Userinfo","USERINFO","ui","Ui","UI"])
@commands.has_any_role('Moderatori', 'Triumvirato', 'Co-Triumvirato', 'Senatori', '690956686147453048')
async def userinfo(ctx, user: discord.Member):
guild = ctx.guild
#ruoli-principali
triumvirato = get(guild.roles, id=int("690951634183782461"))
co_triumvirato = get(guild.roles, id=int("690954867346243624"))
presidente = get(guild.roles, id=int("690956686147453048"))
senatore = get(guild.roles, id=int("690960692051705896"))
moderatore = get(guild.roles, id=int("700353561392971877"))
membro = get(guild.roles, id=int("690963300707729408"))
accademico = get(guild.roles, id=int("690964416644251750"))
onorario = get(guild.roles, id=int("690965300769980476"))
gamer = get(guild.roles, id=int("724978599266091028"))
clandestino = get(guild.roles, id=int("690972809219801088"))
#ruoli-attività
storico = get(guild.roles, id=int("690967861404893234"))
boosters = get(guild.roles, id=int("726498072581898250"))
veterano = get(guild.roles, id=int("690962271962267758"))
rilevante = get(guild.roles, id=int("690962450211799070"))
attivo = get(guild.roles, id=int("690962456897650755"))
presente = get(guild.roles, id=int("690962769511710811"))
ambientato = get(guild.roles, id=int("690962461255270440"))
recluta = get(guild.roles, id=int("690962671847342171"))
#settaggio ruoli
official_roles = clandestino, onorario, gamer, accademico, membro, moderatore, senatore, presidente, co_triumvirato, triumvirato
official_highest = discord.utils.find(lambda role: role in official_roles, reversed(user.roles))
activity_roles = recluta, ambientato, presente, attivo, rilevante, veterano, boosters, storico
activity_highest = discord.utils.find(lambda role: role in activity_roles, reversed(user.roles))
#esecuzione comando
embed = discord.Embed(
title=f'Informazioni su {user}',
timestamp=ctx.message.created_at,
color=user.color
)
embed.set_footer(
text=f'Richiesto da: {ctx.author}',
icon_url=ctx.author.avatar_url
)
embed.set_thumbnail(url=user.avatar_url)
embed.add_field(
name='ID utente:',
value=user.id,
inline=False
)
embed.add_field(
name='Nome utente:',
value=user.display_name,
inline=False
)
embed.add_field(
name='Account creato il:',
value=user.created_at.strftime("%a, %d %B %Y, %I:%M %p CET"),
inline=False
)
embed.add_field(
name="L'utente è entrato nel server il:",
value=user.joined_at.strftime("%a, %d %B %Y, %I:%M %p CET"),
inline=False
)
embed.add_field(
name="Ruolo ufficiale:",
value=f'{official_highest.mention}',
inline=False
)
embed.add_field(
name="Ruolo attività:",
value=f'{activity_highest.mention}',
inline=False
)
embed.add_field(
name="E' un bot:",
value=user.bot,
inline=False
)
await ctx.send(embed=embed)

我说的正是代码的这一部分:

official_roles = clandestino, onorario, gamer, accademico, membro, moderatore, senatore, presidente, co_triumvirato, triumvirato
official_highest = discord.utils.find(lambda role: role in official_roles, reversed(user.roles))
activity_roles = recluta, ambientato, presente, attivo, rilevante, veterano, boosters, storico
activity_highest = discord.utils.find(lambda role: role in activity_roles, reversed(user.roles))

在CCD_ 1的抵抗下,选择了一个不受欢迎的人;无";波索来了吗?

您可以检查它并给出一些默认值:

official_mention = official_highest.mention if official_highest else "None"

相关内容

  • 没有找到相关文章

最新更新