'Python Discord bot fails to log links and images

I am trying to log only site-links and image-links posted (whilst ignoring chat or banter) to one of my Discord servers and created a simple Python Discord bot to do this. It successfully saves a lot of the site-links and image-links to file. However a lot of other links, particularly ones which were posted 'en masse' by users (i.e. attached multiple images or links to a single message) failed to be logged.

Here's my simple bot:

import discord
import asyncio
import os

#Initializes the bot to accept commands.
client = discord.Client()

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')

@client.event
async def on_message(message):
    if message.author != client.user:   #This prevents a self-propogating echo chamber of text!

        if(message.content == "log_channel"):
            async for message in client.logs_from(message.channel, limit=5000000, reverse=True):
                with open(os.getcwd()+"/logs.txt", "a") as output_file: 
                    if("http" in message.content): output_file.write(message.content+"\n")

client.run(xxx-xxx-xxx)

What could I do to ensure even those messages that contain multiple images and links get logged accurately?



Solution 1:[1]

I believe you would have to check if the message is an embed or a link and then log it and check if the message is anything else then embed or link ignore it

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 emil