# Buggy code
async def find_linked_message_from_dm(self, message, either_direction=False):
    if either_direction and message.embeds:
        compare_url = message.embeds[0].author.url
        compare_id = compare_url.split("#")[-1]
    else:
        compare_url = None
        compare_id = None

    if self.channel is not None:
        async for linked_message in self.channel.history():
            if not linked_message.embeds:
                continue
            url = linked_message.embeds[0].author.url
            if not url:
                continue
            if url == compare_url:
                return linked_message

            msg_id = url.split("#")[-1]
            if not msg_id.isdigit():
                continue
            msg_id = int(msg_id)
            if int(msg_id) == message.id:
                return linked_message

            if compare_id is not None and compare_id.isdigit():
                if int(msg_id) == int(compare_id):
                    return linked_message

        raise ValueError("Thread channel message not found.")


# Traceback (AttributeError)
2021-01-09T15:38:32.286633+00:00 app[worker.1]: 01/09/21 15:38:32 __main__[1402] - ERROR: Ignoring exception in on_raw_reaction_add.
2021-01-09T15:38:32.288758+00:00 app[worker.1]: 01/09/21 15:38:32 __main__[1403] - ERROR: Unexpected exception:
2021-01-09T15:38:32.288760+00:00 app[worker.1]: Traceback (most recent call last):
2021-01-09T15:38:32.288761+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/discord/client.py", line 343, in _run_event
2021-01-09T15:38:32.288762+00:00 app[worker.1]:     await coro(*args, **kwargs)
2021-01-09T15:38:32.288762+00:00 app[worker.1]:   File "/app/bot.py", line 1223, in on_raw_reaction_add
2021-01-09T15:38:32.288763+00:00 app[worker.1]:     await self.handle_reaction_events(payload)
2021-01-09T15:38:32.288763+00:00 app[worker.1]:   File "/app/bot.py", line 1193, in handle_reaction_events
2021-01-09T15:38:32.288764+00:00 app[worker.1]:     linked_message = await thread.find_linked_message_from_dm(
2021-01-09T15:38:32.288764+00:00 app[worker.1]:   File "/app/core/thread.py", line 663, in find_linked_message_from_dm
2021-01-09T15:38:32.288765+00:00 app[worker.1]:     compare_id = compare_url.split("#")[-1]
2021-01-09T15:38:32.288765+00:00 app[worker.1]: AttributeError: '_EmptyEmbed' object has no attribute 'split'

# Fixed code
async def find_linked_message_from_dm(self, message, either_direction=False):
    if either_direction and message.embeds and message.embeds[0].author.url:
        compare_url = message.embeds[0].author.url
        compare_id = compare_url.split("#")[-1]
    else:
        compare_url = None
        compare_id = None

    if self.channel is not None:
        async for linked_message in self.channel.history():
            if not linked_message.embeds:
                continue
            url = linked_message.embeds[0].author.url
            if not url:
                continue
            if url == compare_url:
                return linked_message

            msg_id = url.split("#")[-1]
            if not msg_id.isdigit():
                continue
            msg_id = int(msg_id)
            if int(msg_id) == message.id:
                return linked_message

            if compare_id is not None and compare_id.isdigit():
                if int(msg_id) == int(compare_id):
                    return linked_message

        raise ValueError("Thread channel message not found.")