(This is my first post by the way <3) I am making a discord.py bot and I want a command that will either list warnings (warnings list ) for a user, clear warnings for a user (warnings clear ) or give a help message for the command (anything that does not fit the other two commands)! Here is the code:
JavaScript
x
23
23
1
@commands.command(name="warnings")
2
async def warnings(self, ctx, usage, user):
3
if usage == "clear":
4
f = open(user + ".txt", "w")
5
f.write("")
6
f.close()
7
embed = discord.Embed(title="Warnings removed", description=f"I have removed all warnings for <@!{user}>", colour=discord.Colour.green())
8
await ctx.channel.send(embed=embed)
9
elif usage == "list":
10
try:
11
f = open(user + ".txt", "r")
12
readResult = f.read()
13
if readResult.startswith("Reason: "):
14
embed = discord.Embed(title="Warnings for: <@!" + user + ">", description=readResult, colour=discord.Colour.red())
15
await ctx.channel.send(embed=embed)
16
else:
17
embed = discord.Embed(title="This user has no warnings", colour=discord.Colour.green())
18
await ctx.channel.send(embed=embed)
19
except:
20
embed = discord.Embed(title="This user has no warnings", colour=discord.Colour.green())
21
await ctx.channel.send(embed=embed)
22
23
I have tried an if statement and using @warnings.error but it has not worked, I have also searched the previous questions with this same error message but they are not quite the same! :( By the way the code itself isnt the problem :)
What I expect:
!warnings
JavaScript
1
2
1
>[Something help info.]
2
What I get:
JavaScript
1
3
1
raise MissingRequiredArgument(param)
2
discord.ext.commands.errors.MissingRequiredArgument: usage is a required argument that is missing.
3
Advertisement
Answer
use param=None
to do a sub command, maybe you can search how to make a custom help
, that’ll help you.
JavaScript
1
9
1
@commands.command(name="warnings")
2
async def warnings(self, ctx, usage=None, user=None):
3
4
if usage is None:
5
pass # do something here
6
elif usage == "clear":
7
f = open(user + ".txt", "w")
8
9