簡體   English   中英

Bot 沒有響應給定的輸入 (Discord.py)

[英]Bot is not responding to the input given (Discord.py)

我在 Discord.py 中觀看了有關如何從用戶那里獲取輸入的教程。 然而,機器人不會響應給它的輸入。

機器人發送“這是一個機器人測試。類型(是/否)”消息。 但是當我輸入“是”或“否”時,它沒有響應。

@client.command()
async def bot(ctx):
    await ctx.channel.send("This is a bot test. Type (YES/NO)")

    try:
        message = await bot.wait_for("message", check=lambda m: m.author == ctx.author and m.channel == ctx.channel, timeout=30.0)
  
    except asyncio.TimeoutError:
        await ctx.channel.send("I have been ignored")

    else:
        if message.content.lower() == "yes":
            await ctx.channel.send("The test was succesfull!")
    
        elif message.content.lower() == "no":
            await ctx.channel.send("Thank you for your response")
    
        else:
            await ctx.channel.send("I cannot understand you")

您正在使用client進行裝飾,但在 function 中調用bot

改變


@client.command()
async def bot(ctx):
    await ctx.channel.send("This is a bot test. Type (YES/NO)")

    try:
        message = await bot.wait_for("message", check=lambda m: m.author == ctx.author and m.channel == ctx.channel, timeout=30.0)

@client.command()
async def bot(ctx):
    await ctx.channel.send("This is a bot test. Type (YES/NO)")

    try:
        message = await client.wait_for("message", check=lambda m: m.author == ctx.author and m.channel == ctx.channel, timeout=30.0)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM