TypeError: context menu callback 'slash' requires 2 parameters, first one being the interaction and other one explicitly annotated with discord.User

Viewed 31

I want with this application code it to send a message to channel it is used and delete the channel

@tree.context_menu(guild=discord.Object(id=941748573937209344), name='tester')
async def slash(interaction: discord.Interaction, ctx, user: discord.User):
    title = "ID deleted."
    embed = discord.Embed(title=title, color=0xf1c40f)
    msg = await ctx.send(embed=embed)
    await asyncio.sleep(2)
    channel = ctx.channel
    await channel.delete()

but when I run it, I get the following error:

TypeError: context menu callback 'slash' requires 2 parameters, the first one being the interaction and the other one explicitly annotated with either discord.Message, discord.User, discord.Member, or a typing.Union of discord.Member and discord.User

it works when I delete ctx, but I can't send a message to the channel it's using and then make it delete the channel

can I use something else instead of ctx or where else can I write ctx

1 Answers

You should use the interaction object to get your channel object instead of ctx.

@tree.context_menu(guild=discord.Object(id=941748573937209344), name='tester')
async def slash(interaction: discord.Interaction, user: discord.User):
    title = "ID deleted."
    embed = discord.Embed(title=title, color=0xf1c40f)
    msg = await interaction.response.send_message(embed=embed)
    await asyncio.sleep(2)
    channel = interaction.channel
    await channel.delete()
Related