'How do i make my discord.py bot react to all images sent in a channel

I am using this code but it crashes when i launch it, i want the bot to react with the custom emoji from my server (:okay:) to every image sent in a specific channel. Anyone knows why?

import discord
from discord.ext    import commands
from discord.ext.commands   import Bot
import asyncio
 
bot = commands.Bot(command_prefix = '//')
 
@bot.event
async def on_ready():
    print ("I have awoken")

async def react(message):
    custom_emojis = [
    "<:okay:942697477507801098>"                                                                               
    ]
    guild_emoji_names = [str(guild_emoji) for guild_emoji in message.guild.emojis]
    for emoji in custom_emojis:
        #print(emoji, guild_emoji_names)                
        #print(emoji in guild_emoji_names)
        if emoji in guild_emoji_names:
            await message.add_reaction(emoji)

@bot.event                                             
async def on_message(message):
    if message.channel.id == 929345014205653014: and \
    if message.attachment:
        await react(message)

   


Solution 1:[1]

You need to have the message_content intent enabled to receive message attachments.

intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix = '//', intents=intents)

There is no attachment attribute in the Message class it's, attachments instead. Also, this is how you use and operator in an if statement:

if message.channel.id == 929345014205653014 and message.attachments:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bagle