简体   繁体   中英

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

I watched a tutorial on how to get Input from users in Discord.py. The bot however, does not respond to the input given to it.

The bot sends the "This is a bot test. Type (YES/NO)" message. But when I type "yes" or "no" it does not respond.

@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")

You're decorating with client but calling bot in your function.

Change


@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)

To

@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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM