Reply to a message discord.py

21,930

Solution 1

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

Solution 2

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

Share:
21,930
Legacy Coding
Author by

Legacy Coding

Hi, Im a fairly new programmer, and I also stream to twitch https://twitch.tv/danhowe0

Updated on August 21, 2022

Comments

  • Legacy Coding
    Legacy Coding almost 2 years

    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

  • Legacy Coding
    Legacy Coding over 3 years
    No i know that to send a message you can use that, but i want it to specifically reply to the message, like when you right click on a message and press reply
  • Legacy Coding
    Legacy Coding over 3 years
    Hi, when i say "reply" i mean reply as in a user would right click and press reply
  • Zeref
    Zeref over 3 years
    What version of discord.py do you use? The documentation says that it was added in version 1.6.
  • Zeref
    Zeref over 3 years
    I don't know if this has to do with me using PyCharm but according to it, the latest version of discord.py is 1.5.1, so maybe it's something that hasn't been implemented yet.
  • shellbyy
    shellbyy over 3 years
    ah I got you. I do apologize, but I'm not sure how one would go about doing that :( I will be following this though so that if someone has figured out a way, then I can learn something new too :)
  • Nicholas Chen
    Nicholas Chen about 3 years
    I got an error saying that AttributeError: 'Context' object has no attribute 'reply', can someone help?
  • Frederick Reynolds
    Frederick Reynolds about 3 years
    @NicholasChen You need to update to discord.py 1.6
  • Nicholas Chen
    Nicholas Chen about 3 years
    Thanks, I'll do that