Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

discord.py add reaction to own message

trying to make the bot react to its own messages
discord-python discord-python
discord-python

As the title says, I am trying to make the bot react to its own messages. Here is my example code so far:

from inspect import CO_NESTED
from typing import Literal
from discord.ext import commands
import discord
import random
import asyncio
import time

TOKEN = "xxx"

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    username = str(message.author).split('#')[0]
    user_message = str(message.content)
    channel = str(message.channel.name)
    print(f'{username}: {user_message} ({channel})')

    if message.author == client.user:
        return
    
    if "p!react" in user_message.lower():
        await message.channel.send("hello!")
        await message.add_reaction("đź“°")


client.run(TOKEN)

However, this reacts to the user’s message, not the bot’s. Any help you could give would be greatly appreciated!

>Solution :

.send() returns a new Message object of the message sent. You’ll want to add the reaction to that message instead.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

new_msg = await message.channel.send("hello!")
await new_msg.add_reaction("đź“°")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading