Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reply to a message discord.py

Tags:

python

discord

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

like image 436
Legacy Coding Avatar asked Dec 14 '20 16:12

Legacy Coding


People also ask

How do I reply to a specific message in discord?

How do I use the Reply feature? To reply to a message directly, simply click on the Reply button when you hover over a message. You can also access the reply feature by clicking the three dots on the side of the message or by right-clicking the specific message.


2 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

like image 176
Frederick Reynolds Avatar answered Oct 18 '22 21:10

Frederick Reynolds


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

like image 38
msi Avatar answered Oct 18 '22 20:10

msi