1 回答
TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個(gè)贊
當(dāng)輸入第一個(gè)命令時(shí),使用某種外部狀態(tài)(例如,全局變量)來(lái)跟蹤這個(gè)事實(shí)。您對(duì)on_message第一個(gè)命令的響應(yīng)與對(duì)第二個(gè)命令的響應(yīng)相同,因此它需要查看該外部狀態(tài)并決定相應(yīng)地執(zhí)行什么操作。一個(gè)快速的、即興的、未經(jīng)測(cè)試的(因?yàn)槲覜](méi)有設(shè)置 discord.py)示例:
in_progress = False
async def on_message(message):
if message.author == client.user:
return
elif "start" in message.content and not in_progress:
in_progress = True
await message.channel.send("You said `start`. Waiting for you to say `stop`.")
elif "stop" in message.content and in_progress:
in_progress = False
await message.channel.send("You said `stop`. Waiting for you to `start` again.")
添加回答
舉報(bào)
