#on_raw_message_edit

1 messages · Page 1 of 1 (latest)

autumn swallow
#

if i print(payload)

i get this

<RawMessageUpdateEvent message_id=1363969312791986276 channel_id=1206685947194908705 guild_id=1206685947194908702 data={'type': 0, 'tts': False, 'timestamp': '2025-04-21T20:07:05.494000+00:00', 'pinned': False, 'mentions': [], 'mention_roles': [], 'mention_everyone': False, 'member': {'roles': ['1233886237836967976', '1238604427120873532'], 'premium_since': None, 'pending': False, 'nick': None, 'mute': False, 'joined_at': '2025-04-07T19:38:35.173000+00:00', 'flags': 0, 'deaf': False, 'communication_disabled_until': None, 'banner': None, 'avatar': None}, 'id': '1363969312791986276', 'flags': 0, 'embeds': [], 'edited_timestamp': '2025-04-21T20:07:07.092941+00:00', 'content': 'testing', 'components': [], 'channel_type': 0, 'channel_id': '1206685947194908705', 'author': {'username': 'flytips', 'public_flags': 0, 'primary_guild': None, 'id': '1343293676574474354', 'global_name': None, 'discriminator': '0', 'collectibles': None, 'clan': None, 'avatar_decoration_data': None, 'avatar': '51ebac69ed290bbeaf02b2ed183244d9'}, 'attachments': [], 'guild_id': '1206685947194908702'} cached_message=<Message id=1363969312791986276 channel=<TextChannel id=1206685947194908705 name='⭐-chat' position=2 nsfw=False news=False category_id=1206685947194908703 default_auto_archive_duration=1440 flags=<ChannelFlags value=0>> type=<MessageType.default: 0> author=<Member id=1343293676574474354 name='flytips' global_name=None discriminator='0' bot=False nick=None guild=<Guild id=1206685947194908702 name="xxx" shard_id=0 chunked=True member_count=35>> flags=<MessageFlags value=0>>>
#

but with "on_message_edit" i can just call "before, after"

#

and get the before and after

proper holly
#

No

autumn swallow
# proper holly No

is that a reason to use the "on_raw_message_edit" rather than the standard version?

#

like what is the advantage

#

just so its always in the bots cache?

proper holly
#

on_raw_message_edit always triggers regardless of cache

autumn swallow
# proper holly `on_raw_message_edit` always triggers regardless of cache

theoritcally, this is so probably over engineered and there is probably a easier way to do it, if i made it so the bot caches the message in a custom made cache such as below, and i can call the "on_raw_message_edit" and just retrieve the before from this cache if its not in the bot's cache


class Caching:
    def __init__(self, bot):
        self.bot = bot
        self.cache = {}
        self.clearCacheLoop.start()


    @loop(seconds=30)
    async def clearCacheLoop(self):
        for cacheName, cache in self.cache.items():
            clearCount = len(cache)
            cache.clear()
            cacheLog.info(f'Cleared: {clearCount} items from cache: {cacheName}')

    def registerCache(self, name, cacheDict):
        self.cache[name] = cacheDict
    
    def clearGuildCache(self, guildID):
        for cacheName, cache in self.cache.items():
            if guildID in cache:
                cache.pop(guildID, None)
                cacheLog.info(f"Cleared cache for guild {guildID} in {cacheName}")

    def cogUnload(self):
        self.clearCacheLoop.cancel()
    
    @clearCacheLoop.before_loop
    async def beforeCacheLoop(self):
        await self.bot.wait_until_ready()
proper holly
#

you can access bot._connection._messages which is Deque[Message]

#

though this is discouraged because its library internals

autumn swallow
proper holly
#

probably

autumn swallow
#

okay, that'll work for now, cross the other bridge when i come to it, thanks

#

!tl

#

is there a command to lock threads?

crisp kernel
#

</solved:1025480784188027021>

restive sableBOT
#
Solved!

Marked the thread as solved. If your question has not been answered, please open a new thread in #1019642966526140566.