#Rejecting converter input

1 messages · Page 1 of 1 (latest)

graceful relic
#

Hey, I want to create an argument in a slashcommand that takes a certain form. I've found out about converters, but I can't seem to find how to reject an input
(e.g. if you have a Member option, and you type something that's not a valid member, discord says "Not a valid user.". I'd like something like that)

What I currently tried:

class MoneyConverter(Converter[int]):
    async def convert(self, ctx, argument: str) -> int:
        amount = -1
        try:
            if(argument[-1] == "k"):
                amount = int(argument[:-1])
            elif(argument[-1] == "m"):
                amount = round(1000*float(argument[:-1]))
            else:
                amount = int(argument)
        except:
            raise BadArgument(argument)
        if round(amount,-2) != amount:
            raise BadArgument(argument)
        return amount
        

However, raising an exception doesn't give the result I wanted

modern flax
#

this is error in command not in the class

#

just add this

#

async def balance(user:discord.Member):

#

@graceful relic

graceful relic
#

my thing isn't a member though, I want it to be a custom class / parser

graceful relic
#

Right now I have


@createorder.error
async def info_error(ctx, error):
    if isinstance(error, BadArgument):
        await ctx.respond(f'Invalid money amount entered: {error}')

but this only responds to the command when it's sent, rather than making sure the syntax is correct before it's sent like what's done with members, ints, etc

modern flax
graceful relic
#

I currently have

async def setbalance(ctx,
                  amount: Option(MoneyConverter, description="Amount of money to set the balance to"),
... ):

However, when my money converter doesn't succeed in parsing the input, it currently sends an error after the message was sent. I want it to happen before it's sent (almost like a validator)

sturdy dirge
#

discord does not support bot-side validation of option values

#

most you can do is send a response with the error in text after the command is run

graceful relic