user13518719
user13518719

Reputation:

How do I add a reaction to a message in a specific channel

I am trying to make a bot for a friend so that when someone posts an image in a specific channel, the bot will add a reaction. This is my code for it so far:

@bot.event
async def on_message(client, channel, message):
    channel = 830207256418058330
    pic_ext = ['.jpg','.png','.jpeg']
    if len(message.attachments) > 0: #Checks if there are attachments
        for file in message.attachments:
            for ext in pic_ext:
                if file.filename.endswith(ext):
                    print(f"This message has an Image called: {file.filename}")
                    await message.channel.add_reaction(tu)
                    await message.channel.add_reaction(td)
                    await message.channel.add_reaction(fire)
                    await message.channel.add_reaction(bl)

This is the error I am receiving:

TypeError: on_message() missing 2 required positional arguments: 'channel' and 'message'

Upvotes: 0

Views: 76

Answers (1)

Bagle
Bagle

Reputation: 2346

As Łukasz said in the comments, on_message only takes message as an argument. This will solve the TypeError in your question.

Using your channel id, from your variable channel, you can check whether the channel the message was sent in, message.channel, is equal to this id. If it is, you add the reaction to the message, via message.add_reaction.

@bot.event
async def on_message(message):
    channel = 830207256418058330
    pic_ext = ['.jpg','.png','.jpeg']
    if message.channel.id == channel: # if the channel message was sent in matches the given id
        # then your other code here

Upvotes: 1

Related Questions