所以我要使用Python制作一个不和谐的机器人,我想使其循环直到满足某些条件为止,这是一个简单的示例,只是为了阐明我要尝试的内容。
@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)
甚至在我回答之前,它总是一直问(“你叫什么名字?”)。 希望你能帮我这个忙。
答案 0 :(得分:1)
您已经使它复杂化了。这样做:
@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”)
通常就是这样,是在手机上写的,所以可能有一些语法问题,但是没什么大问题。
答案 1 :(得分:0)
您应该能够通过添加返回值或循环,中断的情况来修复它
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)