【问题标题】:Error code with discord .py带有不和谐 .py 的错误代码
【发布时间】:2018-08-06 10:05:29
【问题描述】:
 @bot.command(pass_conetext = True)
async def info(ctx,  user: discord.Member):
    embed = discord.Embed(title = "Super Bot", description = "Thinking" , color = 0x00ff00)
    embed.add_field(name = "Name", value = user.name, inline = True)
    embed.add_field(name = "ID", value = user.id , inline = True)
    embed.add_field(name = "Status", value = user.status , inline = True)
    embed.add_field(name = "Highest Role", value = user.top_role , inline = True)
    embed.add_field(name = "Joined", value = user.joined_at , inline = True)
    embed.set_thumbnail(url = user.avatar_url)

每次我运行这段代码时都会返回这个错误,我不知道为什么

Ignoring exception in command info
Traceback (most recent call last):
  File "C:\Users\Stuart\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\bot.py", line 846, in process_commands
    yield from command.invoke(ctx)
  File "C:\Users\Stuart\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 367, in invoke
    yield from self.prepare(ctx)
  File "C:\Users\Stuart\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 345, in prepare
    yield from self._parse_arguments(ctx)
  File "C:\Users\Stuart\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 304, in _parse_arguments
    transformed = yield from self.transform(ctx, param)
  File "C:\Users\Stuart\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 212, in transform
    raise MissingRequiredArgument('{0.name} is a required argument that is missing.'.format(param))
discord.ext.commands.errors.MissingRequiredArgument: user is a required argument that is missing.

有人能解释一下原因吗,也许是一个解决方案

【问题讨论】:

  • 你是如何调用命令的?你在 Discord 中输入什么来运行命令?
  • 运行命令是不是
  • 你拼错了pass_conetext,它应该是pass_context。这可能会影响传递给命令的参数
  • 已经解决了这个谢谢

标签: python python-3.x error-handling discord.py


【解决方案1】:

运行该命令的人没有user 参数。

!info @user 而不是!info

【讨论】:

    【解决方案2】:

    你可以把你的代码改成这样来拒绝错误:

    @bot.command(pass_context= True)
    async def info(ctx,  user: discord.Member=None):
        if user is None:
            user = ctx.message.author
        embed = discord.Embed(title = "Super Bot", description = "Thinking" , color = 0x00ff00)
        embed.add_field(name = "Name", value = user.name, inline = True)
        embed.add_field(name = "ID", value = user.id , inline = True)
        embed.add_field(name = "Status", value = user.status , inline = True)
        embed.add_field(name = "Highest Role", value = user.top_role , inline = True)
        embed.add_field(name = "Joined", value = user.joined_at , inline = True)
        embed.set_thumbnail(url = user.avatar_url)
    

    基本上,如果用户什么都不是,它会给消息作者信息..

    【讨论】:

      猜你喜欢
      • 2021-11-20
      • 1970-01-01
      • 2020-12-17
      • 2020-11-28
      • 2022-08-16
      • 1970-01-01
      • 2020-10-18
      • 2021-09-27
      • 2019-11-04
      相关资源
      最近更新 更多