Python 不和谐机器人永远循环
所以我用Python制作了一个discord机器人,我想让它循环直到满足一些条件,这是一个简单的例子,只是为了让我想做的更清楚Python 不和谐机器人永远循环,python,loops,bots,discord,discord.py,Python,Loops,Bots,Discord,Discord.py,所以我用Python制作了一个discord机器人,我想让它循环直到满足一些条件,这是一个简单的例子,只是为了让我想做的更清楚 @bot.command(name='join') async def Yacine(ctx): user = bot.get_user(ID) await user.send("What is your name ?") @bot.event async def on_message(message): if message.content == "Yacin
@bot.command(name='join')
async def Yacine(ctx):
user = bot.get_user(ID)
await user.send("What is your name ?")
@bot.event
async def on_message(message):
if message.content == "Yacine":
user = bot.get_user(ID)
await user.send("Great name")
所以,在它回答我(“伟大的名字”)之后,我希望它在我尝试时再次从顶部提问
@bot.command(name='join')
async def Yacine(ctx):
user = bot.get_user(ID)
await user.send("What is your name ?")
@bot.event
async def on_message(message):
if message.content == "Yacine":
user = bot.get_user(ID)
await user.send("Great name")
Yacine(ctx)
甚至在我回答之前,它一直在问:“你叫什么名字?”。
希望您能帮我解决这个问题。您应该能够通过添加一个返回或在循环的情况下添加一个中断来修复它
async def Yacine(ctx):
user = bot.get_user(ID)
await user.send("What is your name ?")
@bot.event
async def on_message(message):
if message.content == "Yacine":
user = bot.get_user(ID)
await user.send("Great name")
return
Yacine(ctx)
你把事情复杂化了。这样做:
@bot.command(name='join')
async def Yacine(ctx):
user = bot.get_user(ID)
await user.send("What is your name ?")
msg = await client.wait_for('message', check=lambda message: message.author == ctx.author)
if “Yacine” in msg.content:
await user.send(“Great name”)
这是我在手机上写的,所以可能有一些语法问题,但没什么大问题。您的代码有缩进问题。请更新问题。