Home > OS >  discord.py report system discord.py | MissingRequiredArgument
discord.py report system discord.py | MissingRequiredArgument

Time:08-17

Okay so I think I got the right code down but I don't know what argument to use. If anyone can help please do.

Code:

@client.command()
async def report(ctx, *, report):
  # values
  user = ctx.author
  server = ctx.guild.name
  channel = client.get_channel(1009201586586783785)
  # Report Text
  if report == None:
      # Error
      await ctx.send("Enter your report! example : r!report {your report here}")
  else:
      # Success
      await ctx.send("We have sent your report to **DisReport Hub** to be reviewed!")
      report = discord.Embed(title=f"{user.name} sent an report!", description="-----", color=discord.Colour.blurple())
      report.add_field(name=f"Report from - {server}: ", value=f"{report}")
      await channel.send(embed=report)

Error message:

 line 542, in transform
    raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: report is a required argument that is missing.

CodePudding user response:

You need to explicitly give it a default of None if want it to default. Otherwise, it will give you that exception, which will lead to the error being printed to the console if it wasn't already handled.

@client.command()
async def report(ctx, *, report: str = None):
  # values
  user = ctx.author
  server = ctx.guild.name
  channel = client.get_channel(1009201586586783785)
  # Report Text
  if report is None:  # sidenote: prefer `is` when comparing to `None`
      # Error
      await ctx.send("Enter your report! example : r!report {your report here}")
  else:
      # Success
      await ctx.send("We have sent your report to **DisReport Hub** to be reviewed!")
      report = discord.Embed(title=f"{user.name} sent an report!", description="-----", color=discord.Colour.blurple())
      report.add_field(name=f"Report from - {server}: ", value=f"{report}")
      await channel.send(embed=report)
  • Related