Resolving type annotation issues for my Discord bot in Python

I’m encountering a type error with my Discord bot. It says that the ‘reason’ parameter is missing a type annotation in my command function whenever I run the bot. Here’s a snippet of my code:

@app_commands.command(name='kick', description='Kicks a chosen member if you have the right permissions.')
@has_permissions(kick_members=True)
async def kick(context, interaction: discord.Interaction, member: discord.Member, *, reason='None'):
    await interaction.response.send_message(f'{member} has been kicked from the server.')
    await member.kick(reason=reason)

@kick.error
async def kick_error(context, interaction: discord.Interaction, error):
    if isinstance(error, commands.MissingPermissions):
        await interaction.response.send_message('You lack the permissions to kick users!')

The message I’m getting states that the ‘reason’ parameter is still not annotated. I don’t see what’s wrong since I’ve set a default value. I also tried adding a return type annotation, but that didn’t fix it either. Can someone guide me on how to correctly use type hints for optional parameters in this context?

you’re mixing regular command syntax with slash command syntax. for app_commands, drop the context parameter completely. also fix your reason annotation: reason: str = 'None'. your function should look like: async def kick(interaction: discord.Interaction, member: discord.Member, reason: str = 'None'):

You need to add a type hint to your reason parameter. Python wants all parameters annotated when strict type checking is on. Change it to reason: str = 'None' instead of *, reason='None'. Also, having both context and interaction parameters is weird - pick one. Use context for regular commands or interaction for slash commands. For slash commands, you only need interaction. Just add : str to your reason parameter and you’re good.