what i want to do is something like this:
have a command modifyImage
@commands.command()
async def modifyImage(ctx: Context, imgName: DefaultImageConverter, size: int):
img = imageList[imgName]
img.scale(size)
a command setDefaltImage
@commands.command()
async def setdefaultImage(ctx: Context, imgName: str):
global defaultImg
defaultImg = imgName
and a converter DefaultImageConverter
class DefaultImageConverter(commands.Converter):
async def convert(self, ctx, imgName):
if imgName not in imageList:
if defaultImg != '':
return defaultImg
if defaultImg == '':
ctx.reply("you didn't pass a image and doesn't have a defalt image")
raise BadArgument
elif imgName in imageList:
return imgName
the DefaultImageConverter
would be a converter that checks the a image exist and return them, if not, return the default image if exist, if even that doesn't existe, he will raise a error
but the program doesn't work this way, because if i use the command !modifyImage 100
the number '100' won't be passed to the parameter size
, because technically the conversion worked
so i need to do
@commands.command()
async def modifyImage(ctx: Context, imgName: typing.Optional[DefaultImageConverter], size: int):
if imgName == None:
if defaultImg != '':
imgName = defaultImg
else:
ctx.send("you didn't pass a image and doesn't have a defalt image")
return
img = imageList[imgName]
img.scale(size)
and the converter be
class DefaultImageConverter(commands.Converter):
async def convert(self, ctx, imgName):
if imgName not in imageList:
return BadArgument
else:
return imgName
what i need to do for use something like the first option, because the if imgName == None:
part become very repetetive, and every function that modify a image has this
tl;dr
i want a way to do a discord.py converter, at the same time, return a value, and pass the current argument value to the next parameter
the only way that i know to the converter 'pass the argument' is using a typing.Optional and raising a error in the converter, but doing this the argument become None
question from:
https://stackoverflow.com/questions/65884376/how-to-make-a-discord-py-converter-pass-thorugh-a-argument-and-time-return-a-val