diff options
author | 2019-12-17 23:18:00 +0100 | |
---|---|---|
committer | 2019-12-17 23:18:00 +0100 | |
commit | c469b82144eacca992647f8321992d66e6bad3c8 (patch) | |
tree | 5e9729739fd335b611e3ddcca051717694b569fc /tests/helpers.py | |
parent | Use OAuth to be Reddit API compliant (#696) (diff) |
Use on_user_update to properly sync users with db
It's important to us that we keep the information we have about users
in the database in sync with the actual user information the bot can
observe in our guild. To do this, we relied on the `on_member_update`
event listener to synchronize a user's information when an update of
the information was detected. However, unfortunately, this does not
work for user account information (i.e., the username, avatar, and
discriminator of the user).
The solution is to use the `on_user_update` event listener to watch
for updates in the user settings and to use the `on_member_update`
event listener to watch for updates in guild-related information for
that user. (We currently only sync the roles the user has.)
See:
- https://discordpy.readthedocs.io/en/stable/api.html#discord.on_member_update
- https://discordpy.readthedocs.io/en/stable/api.html#discord.on_user_update
Note:
The docs for `discord.py` make it *seem* like the `on_member_update`
event does not fire for updates of theusername, discriminator, and
avatar attributes. However, experimentation shows that this event
*does* fire; it's just that the member objects provided as `before`
and `after` to the listener will already have been updated in cache
by the `on_user_update` event that fires *before* it.
This means that if the only changes made were to the username,
avatar, and discriminator, the `on_member_update` event does fire,
but with two *equal* Member objects. This makes it appear as if you
may be able to use `on_member_update`, since it fires, but it does
not actually contain anything useful.
Diffstat (limited to 'tests/helpers.py')
0 files changed, 0 insertions, 0 deletions