How do I send an error message? Discord.py

Asked

Viewed 239 times

-1

Hello, I was making a message with the discord.Embed, only that I want that in case the user does not send the message correctly, the bot send a message Embed error.

I tried this way only that the following mistake: discord.ext.commands.errors.MissingRequiredArgument: user is a required argument that is missing.

@client.command()
async def remcargo (ctx, role: d.Role, user: d.Member):
    embed = d.Embed(
        title='Sucesso',
        description=f"Removido com sucesso {role.mention} from {user.mention}.",
        colour=d.Colour.green()
    )

    fembed = d.Embed(
        title='Erro',
        description=f"Não foi possível realizar o comando, Verifique se digitou corretamente",
        colour=d.Colour.red()
    )
    try:
        if ctx.author.guild_permissions.administrator:
            await user.remove_roles(role)
            await ctx.send(embed=embed)


    except:

        await ctx.send(embed=fembed)

1 answer

0


You are giving this error because in the command constructor the "user" parameter is required. To leave it optional it should look like this: user: d.Member = None

  • Okay, I put this command, only now it’s giving another problem: Unresolved Reset "Nothing"

  • I was wrong instead of Nothing is None. I edited my answer

  • Ok! now it worked! Thank you very much

  • I suggest searching for optional parameters in functions

Browser other questions tagged

You are not signed in. Login or sign up in order to post.