how can I add context menu from app_commands

Viewed 53

I want to add context menu from app_commands, I tried that, but it didn't work

import discord
from discord import app_commands
from discord.ext import commands


@app_commands.context_menu(name="Hello")
    async def hello(interaction: discord.Interaction, message: discord.Message):
        await interaction.response.send_message("Hey !")

I'm using discord.py 2.0.1, how can I add?

1 Answers

Context menu's are a bit tricky to get working, here's an example:

async def hello(interaction: discord.Interaction, message: discord.Message):
    await interaction.response.send_message(f"Hey {message.author.mention}!")

hello_context_menu = app_commands.ContextMenu(
    name='Say Hello',
    callback=hello,
)
bot.tree.add_command(hello_context_menu)
Related