How would I mention a parameter from a function into a f string?

Okay, so I implemented a has_role() function into a command. Code:

@client.command()
@commands.has_role('Cleaner')
async def clear(ctx, amount=5):
    await ctx.channel.purge(limit=amount)

If MissingRole error was to be triggered I would want to send a f-string that mentions the role inside the has_role() function.

@clear.error
async def mr4c(ctx, error):
    if isinstance(error, commands.MissingRole):
#just a special embed to display the error
        mr4cembed=discord.Embed(title='ERROR...', description=f"You do not have the required permission to execute this command!", color=discord.Colour.blue())
        #this is where I would like to mention it
        mr4cembed.set_footer(text=f'You need the {WHAT WOULD I WRITE HERE} role to proceed.')
        await ctx.send(embed=mr4cembed) 

Upvotes: 0

Views: 36

Answers (1)

Fixator10
Fixator10

Reputation: 670

Use missing_role attribute of exception:

@commands.command()
@commands.has_role("Dumb role")
async def test(ctx):
    ...

@test.error
async def handle(ctx, error):
    if isinstance(error, commands.MissingRole):
        await ctx.send(f"Role thats you need is: {error.missing_role}")

Upvotes: 1

Related Questions