When working with on_raw_* events, the only options to get the actual model is to call Client.fetch_* or Client.get_*. I find my self writing utility functions like:
async def get_or_fetch_channel(self, channel_id) -> discord.TextChannel:
return chan if (chan := self.bot.get_channel(channel_id)) is None \
else await self.bot.fetch_channel(channel_id)
How about if these were included with the library? I opened an issue because wasn't sure if you'd like to have them in the library, I can make a PR if you agree on this.
Having those extension functions on the Client class, so one can just say-
channel = await bot.get_or_fetch_channel(channel_id)
Writing a utility function in the project.
Addition of three new functions: Client#get_or_fetch_channel, Client#get_or_fetch_message, Client#get_or_fetch_guild which return the models if they exist in cache or fetch them if not.
Python allows you to do this already without the function boilerplate:
channel = bot.get_channel(channel_id) or await bot.fetch_channel(channel_id)
This is sufficient enough and usually simple enough that having it in the library only buys you character counts which isn't too much when you consider you also have to handle errors and whatever else you're planning on doing.
Most helpful comment
Python allows you to do this already without the function boilerplate:
This is sufficient enough and usually simple enough that having it in the library only buys you character counts which isn't too much when you consider you also have to handle errors and whatever else you're planning on doing.