我如何通知某人缺少争论?

2024-04-26 07:11:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用discord py开发一个discord机器人,其中一个命令是获取某人的个人资料图片。我做的不错,但我有一些问题。 基本上,我想提醒用户,他需要提到他想要照片的那个人,这个论点

代码本身工作得很好,但我想告诉大家,这是必要的

async def avatar(ctx, member: discord.Member):
  show_avatar = discord.Embed(
    title = f'Aqui está a foto dele, senhor {ctx.author}',
    color = 2602879
  )
  show_avatar.set_image(url='{}'.format(member.avatar_url))
  await ctx.send(f'{ctx.author.mention}', embed=show_avatar)```

Tags: 用户py命令urlshow机器人图片照片
1条回答
网友
1楼 · 发布于 2024-04-26 07:11:52

您必须使用errorhandler让他们知道。下面是一个简单的格式,并有一些解释:

@avatar.error # Decorator to specify this is the handler for this command only
async def avatar_handler(ctx, error): # Context and error required
    if isinstance(error, discord.BadArgument): # Check if the exception is what you want to handler
        await ctx.send(f"**Error:**\n{str(error)}") # Customize error however you want. This will just show the error

discord.BadArgument是可以在处理程序中处理的众多异常之一。特别是,如果存在解析或转换错误,将引发此错误

^{}list of exceptionstutorial on handlers

相关问题 更多 >