# Buggy code
async def load_communities(self):
    communities = []

    for raw_community in await self.db.communities():
        _class = getattr(_streamtypes, raw_community["type"], None)
        if not _class:
            continue
        raw_msg_cache = raw_community["messages"]
        raw_community["_messages_cache"] = []
        for raw_msg in raw_msg_cache:
            chn = self.bot.get_channel(raw_msg["channel"])
            msg = await chn.get_message(raw_msg["message"])
            raw_community["_messages_cache"].append(msg)
        token = await self.db.tokens.get_raw(_class.__name__, default=None)
        communities.append(_class(token=token, **raw_community))

    # issue 1191 extended resolution: Remove this after suitable period
    # Fast dedupe below
    seen = set()
    seen_add = seen.add
    return [
        x
        for x in communities
        if not (x.name.lower() in seen or seen_add(x.name.lower()))
    ]


# Traceback (discord.errors.NotFound)
Exception during loading of cog
Traceback (most recent call last):
File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/core/core_commands.py", line 100, in _load
await bot.load_extension(spec)
File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/core/bot.py", line 228, in load_extension
await lib.setup(self)
File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/cogs/streams/__init__.py", line 6, in setup
await cog.initialize()
File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/cogs/streams/streams.py", line 74, in initialize
self.streams = await self.load_streams()
File "/home/jjay/rewrite/lib/python3.6/site-packages/redbot/cogs/streams/streams.py", line 629, in load_streams
msg = await chn.get_message(raw_msg["message"])
File "/home/jjay/rewrite/lib/python3.6/site-packages/discord/abc.py", line 844, in get_message
data = await self._state.http.get_message(channel.id, id)
File "/home/jjay/rewrite/lib/python3.6/site-packages/discord/http.py", line 211, in request
raise NotFound(r, data)
discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Message

# Fixed code
async def load_communities(self):
    communities = []

    for raw_community in await self.db.communities():
        _class = getattr(_streamtypes, raw_community["type"], None)
        if not _class:
            continue
        raw_msg_cache = raw_community["messages"]
        raw_community["_messages_cache"] = []
        for raw_msg in raw_msg_cache:
            chn = self.bot.get_channel(raw_msg["channel"])
            if chn is not None:
                try:
                    msg = await chn.get_message(raw_msg["message"])
                except discord.HTTPException:
                    pass
                else:
                    raw_community["_messages_cache"].append(msg)
        token = await self.db.tokens.get_raw(_class.__name__, default=None)
        communities.append(_class(token=token, **raw_community))

    # issue 1191 extended resolution: Remove this after suitable period
    # Fast dedupe below
    seen = set()
    seen_add = seen.add
    return [
        x
        for x in communities
        if not (x.name.lower() in seen or seen_add(x.name.lower()))
    ]