discord.py report system discord.py | MissingRequiredArgument

Question:

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.
Asked By: CodingSap

||

Answers:

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)
Answered By: Eric Jin
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.