第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在discord.py 的commnad 中進行輸入

如何在discord.py 的commnad 中進行輸入

慕運維8079593 2023-08-15 17:34:16
我正在嘗試創(chuàng)建一個需要輸入的命令。到目前為止,這是我的代碼:@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條經(jīng)驗 獲得超4個贊

只需在 def 中添加另一個參數(shù)即可:


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


查看完整回答
反對 回復(fù) 2023-08-15
?
呼喚遠(yuǎn)方

TA貢獻1856條經(jīng)驗 獲得超11個贊

使用wait_for,您可以等待用戶回復(fù)消息并根據(jù)他們的回復(fù)執(zhí)行某些操作。


@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')


查看完整回答
反對 回復(fù) 2023-08-15
  • 2 回答
  • 0 關(guān)注
  • 163 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號