#how to use both commands?

1 messages · Page 1 of 1 (latest)

jovial linden
#

hallo i wanted an command to be compatible on a prefix and slash but it somehow stops my bot here's the command

@bot.command(name="watch")
@bot.slash_command(name="watch", description="Search for a movie/show and get a watch link.")
async def watch(ctx_or_interaction, *, query=None):
 
    
    if isinstance(ctx_or_interaction, nextcord.Interaction):
        if query is None:
            await ctx_or_interaction.response.send_message("❌ Please provide a search query.", ephemeral=True)
            return
        is_slash = True
    else:
        is_slash = False

    result = await search_tmdb(query)
    if not result:
        if is_slash:
            await ctx_or_interaction.response.send_message("❌ No results found", ephemeral=True)
        else:
            await ctx_or_interaction.send("❌ No results found")
        return

    watch_link, poster_url, title, rating, release_date = result
    embed = nextcord.Embed(title=f"🎬 {title}", color=nextcord.Color.blue(), url=watch_link)

    if poster_url:
        embed.set_image(url=poster_url)

    embed.add_field(name="Rating", value=f" ⭐ {rating}/10", inline=True)
    embed.add_field(name="🗓️ Release Date", value=release_date, inline=True)
    embed.add_field(name="🤸🏻 Watch Now", value=f"[Click here]({watch_link})", inline=False)

    if is_slash:
        await ctx_or_interaction.response.send_message(embed=embed)
    else:
        await ctx_or_interaction.send(embed=embed)
        ```
modest ether
#

it should be something like:

@bot.command(name="watch")
async def watch_prefix(ctx, *, query=None):
    # code


@bot.slash_command(name="watch", description="Search for a movie/show and get a watch link.")
async def watch(interaction, query: str = nextcord.SlashOption(required=True)):    
    result = await search_tmdb(query)
    if not result:
        await interaction.response.send_message(":x: No results found", ephemeral=True)
        return

    watch_link, poster_url, title, rating, release_date = result
    embed = nextcord.Embed(title=f":clapper: {title}", color=nextcord.Color.blue(), url=watch_link)

    if poster_url:
        embed.set_image(url=poster_url)

    embed.add_field(name="Rating", value=f" :star: {rating}/10", inline=True)
    embed.add_field(name=":calendar_spiral: Release Date", value=release_date, inline=True)
    embed.add_field(name=":person_doing_cartwheel_tone1: Watch Now", value=f"[Click here]({watch_link})", inline=False)
    await interaction.response.send_message(embed=embed)
#

code for prefix/slash commands should be separated

jovial linden
#

thanks for help

modest ether
#

and it's recommended to use slash commands, as discord has strict limits for message content intent

modest ether
modest prism
#

You can also create one method and call it from both commands if you just wanted the logic once

#

Although be aware that ctx and interaction objects are different