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

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')
添加回答
舉報