Skip to content

Invite tracking

Invite tracking is a feature introduced in v2.4 that tracks:

  1. On join, which invite was used.
  2. Who created the invite.
  3. When the invite was created.

This information is logged internally and an embed is sent to the channel defined by the invite_alert_channel_id argument of data/variables.json.

How it works

On start EnduraBot gets a list of all invite objects in the server and places them into the bot.invites global list.

There are then 2 listeners that work together:

  • listeners/invites_creation.py
  • listeners/invites_use.py

Creation listener

This listeners listens to the on_invite_create event of the Discord API. As an invite is created it is immediately added to the bot.invites global list.

Use listener

This listener listens to the on_member_join event of the Discord API. When it triggers, EnduraBot reviews it's bot.invites global list, pulls the list of invites from the server again, and then compares both lists to see which invite had it's use count increase. That invite is determined to be the one used.

Once EnduraBot figures out which invite was used, obtaining all the relevant information to log and send in an embed is straight forward. This listener houses the code that does that.

At the end, EnduraBot empties the bot.invites global list and replaces it with the new list it pulled. This ensures EnduraBot is ready for the next time someone joins.