Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 不和谐机器人永远循环_Python_Loops_Bots_Discord_Discord.py - Fatal编程技术网

Python 不和谐机器人永远循环

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

所以我用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 == "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”)

这是我在手机上写的,所以可能有一些语法问题,但没什么大问题。

您的代码有缩进问题。请更新问题。