es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Cómo responder a un mensaje enviado por el propio bot

Quiero que el bot responda a su mensaje de ayuda diciendo “este mensaje está ahora inactivo”.

Aquí está el código:

mm = await message.send(embed=embed1)
await mm.add_reaction("1️⃣")
await mm.add_reaction("2️⃣")
await mm.add_reaction("3️⃣")
try:
    while True:
        reaction, user = await bot.wait_for("reaction_add", check=check, timeout=10)
        if str(reaction.emoji) == "1️⃣":
            await mm.edit(embed=embed1)
        elif str(reaction.emoji) == "2️⃣":
            await mm.edit(embed=embedZ)
        elif str(reaction.emoji) == "3️⃣":
            await mm.edit(embed=embed3)
except asyncio.TimeoutError:
    await mm.reply('...')

error: 'mensaje' object no tiene un atributo llamado 'respuesta'

Tags:  , , ,

Answer

  1. Avatar for davy.ai

    Para hacer que el bot responda a su mensaje de ayuda con “este mensaje está ahora inactivo”, debes reemplazar la línea await mm.reply('...') con await mm.edit(content='este mensaje está ahora inactivo'). Esto se debe a que el objeto message no tiene un atributo reply, pero sí tiene un atributo edit que se puede usar para cambiar el contenido del mensaje. El código actualizado se vería así:

    mm = await message.send(embed=embed1)
    await mm.add_reaction("1️⃣")
    await mm.add_reaction("2️⃣")
    await mm.add_reaction("3️⃣")
    try:
        while True:
            reaction, user = await bot.wait_for("reaction_add", check=check, timeout=10)
            if str(reaction.emoji) == "1️⃣":
                await mm.edit(embed=embed1)
            elif str(reaction.emoji) == "2️⃣":
                await mm.edit(embed=embedZ)
            elif str(reaction.emoji) == "3️⃣":
                await mm.edit(embed=embed3)
    except asyncio.TimeoutError:
        await mm.edit(content='este mensaje está ahora inactivo')
    

Comments are closed.