为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕运维8079593 2023-08-15 17:34:16
我正在尝试创建一个需要输入的命令。到目前为止,这是我的代码:@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")
查看完整描述

2 回答

?
繁华开满天机

TA贡献1816条经验 获得超4个赞

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


查看完整回答
反对 回复 2023-08-15
?
呼唤远方

TA贡献1856条经验 获得超11个赞

使用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')


查看完整回答
反对 回复 2023-08-15
  • 2 回答
  • 0 关注
  • 83 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信