THEMEGACODERS
THEMEGACODERS

Reputation: 93

How do I make a input in a commnad in discord.py

I am trying to make a command that needs input. Here is my code so far:

@bot.command()
async def eat(ctx)
  await ctx.channel.send("What would you like to eat? Apple, Cake, or Cookie?")

And I need a input here so I can do the rest... But here is the rest:

if eat=apple:
  print("You ate an apple!")
elif eat=cake:
  print("You ate Cake!")
elif eat=cookie:
  print("You ate a Cookie!")
else:
  print("Sorry I don't know that food in there. Please try again")

Upvotes: 0

Views: 91

Answers (2)

Jab
Jab

Reputation: 27515

Just add another argument into the def:

@bot.command()
async def eat(ctx, what:str=''):
    if what == apple:
      print("You ate an apple!")
    elif what == cake:
      print("You ate Cake!")
    elif what == cookie:
      print("You ate a Cookie!")
    else:
      print("Sorry I don't know that food in there. Please try again")

Upvotes: 2

Jawad
Jawad

Reputation: 2041

Using wait_for, you can wait for a user to reply to a message and do something based on their reply.

@bot.command()
async def eat(ctx):
    await ctx.send('What would you like to eat? Apple, Cake, or Cookie?')

    msg = await bot.wait_for('message')
    if msg.content == 'Apple'.lower():
        await ctx.send('You ate an apple!')
    elif msg.content == 'Cake'.lower():
        await ctx.send('You ate Cake!')
    elif msg.content == 'Cookie'.lower():
        await ctx.send('You ate a Cookie!')
    else:
        await ctx.send('Sorry I don\'t know that food in there. Please try again')

Upvotes: 1

Related Questions