Reply to a message discord.py

Viewed 33394

I want to make my bot react to a users message when they type a certain sentence.

My code to reply:

await ctx.message.reply("I just replied to you")

I get the error:

ctx.message has no attribute "reply"

What code can I do to make the bot reply to the message?

When I say reply, I mean the same as a user can press reply on a message

5 Answers

To any new user here, as of the 1.6.0 discord.py-rewrite update, you are now able to reply!

Every message or context now has a reply attribute. To reply, simply use

await ctx.reply('Hello!')

You can also not mention the author in the reply with mention_author=False

await ctx.reply('Hello!', mention_author=False)

No reply example Reply example

You can also find a basic example Here

@bot.event
async def on_message(message):
    if message.content == "hi":
        await message.channel.send("hello", reference=message)

The main thing here is reference=message. It is available since Discord.py 1.6.

More info: 1, 2.

Discord.py does not have support for the new "reply" feature yet. Unfortunately, you can't really use the reply feature unless they added it to the libary.

one option is to use a Cog.listener you can find documentation on Cog.listener here, but to answer your question, the way I did my Cog.listener was:

@bot.listen('on_message') 
async def stuff(message):

    if message.content.startswith("buttlerprefix"): # this tells the bot what to listen for. If a user types `buttlerprefix` in any text channel, it will respond with what's below
        msg = await message.channel.send("my prefix is `>`") # set the sending message equal to a variable so that you can manipulate it later like I did with the timer, and delete function below
        await asyncio.sleep(10) # tells the bot to wait 10 seconds before continuing below
        await msg.delete() # deletes the send message after 10 seconds

if you have any further questions, or you encounter any errors that I don't see here, then please follow up with me :)

Try replacing the line with

await ctx.send('I just replied to you')
Related