如何在discord.py 的commnad 中进行输入

我正在尝试创建一个需要输入的命令。到目前为止,这是我的代码:


@bot.command()

async def eat(ctx)

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

我需要在这里输入,以便我可以完成其余的工作...但这是其余的:


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")


慕运维8079593
浏览 131回答 2
2回答

繁华开满天机

只需在 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")

呼唤远方

使用wait_for,您可以等待用户回复消息并根据他们的回复执行某些操作。@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')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python