Luke
Luke

Reputation: 45

How to use options in discord.py?

I'm working on a discord bot that can send random memes, and I wanted to add a command for continuous feed according to a the amount of memes the user wants, for example /feed number:15, would send 15 memes.

The problem is how to make the option input work on the command, I've find some videos that helped me a little, but due to the other commands being híbrido commands, I can figure out how to make this one working.

This is what's I have so far:


@bot.hybrid_command(name = "feed", with_app_command = True, description = "Feeds a specific number of memes")

@app_commands.guilds(discord.Object(id = guild_id))

async def test1(interaction: discord.Interaction, number: int):

    await interaction.response.send_message("It's working!")

The await line, obviously won't do any feed this way, I know, I did the feed part separated and it works, but I just did it this way for testing, so if I type the command and enter a number, it should return me "It's working!", But that never happens, I suppose it's maybe something to do with híbrido commands, but I really don't know, what am I missing?

Upvotes: 1

Views: 697

Answers (1)

Catgal
Catgal

Reputation: 718

I don't think the input option is the problem, because I see nothing wrong with it, but the thing that is surely wrong is that you're naming the first argument of the hybrid command interaction, which is wrong and can create confusion; the actual argument it should be is context or ctx. And that object is a discord.ext.commands.Context object.

You should rename it to ctx to avoid confusion.

@bot.hybrid_command(name = "feed", with_app_command = True, description = "Feeds a specific number of memes")
@app_commands.guilds(discord.Object(id = guild_id))
async def test1(ctx: commands.Context, number: int):
    await ctx.send("It's working!")

You may want to see the official example here

Upvotes: 1

Related Questions