Hey everyone! I’ve got a Discord bot that’s working pretty well. It can chat with people and I even added some cool features like weather reports and time info using slash commands. Everything works great but I’m stuck on one thing.
I want my bot to automatically respond whenever someone posts a picture in any channel. Something simple like “Nice image you shared there!” would be perfect. I’ve been searching around but most of the guides I found are really old and don’t seem to work anymore.
Anyone know how to detect when users upload images and make the bot respond to them? Would really appreciate some help with this!
Been working with Discord bots for a while now and there’s actually a simpler approach than checking file extensions. You can use the attachment.content_type property which gives you the MIME type directly. Image files will have content types starting with ‘image/’ so you can just check if attachment.content_type.startswith('image/'). This method is more reliable because it reads the actual file header rather than relying on extensions, which users can sometimes change or fake. I’ve found this catches all image formats including newer ones like AVIF without having to maintain a list of extensions. Just remember to handle cases where content_type might be None for some attachments, though that’s pretty rare with modern Discord uploads.
I ran into this exact issue when building my moderation bot last year. The key is using the on_message event and checking if the message has attachments with image file extensions. Here’s what works reliably: check message.attachments and then filter by common image extensions like .png, .jpg, .jpeg, .gif, .webp. You can access the filename through attachment.filename and use .lower().endswith() to check the extension. This approach catches actual image uploads rather than just any file attachment, which prevents your bot from responding to random documents or zip files. Make sure to add a check that the message author isn’t your bot itself, otherwise you might create an infinite loop if your bot ever posts images.
yo, just peek at message.attachments in your on_message handler. if there’s any, just respond! this works for pics, vids, all that stuff. you’ll get the hang of it once u see how it’s setup.