Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

discord.py report system discord.py | MissingRequiredArgument

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading