Here you have example schema or storing invites alongside with data about the invites themselves
const inviteSchema = new Schema({
code: String,
uses: Number,
leaves: { type: Number, default: 0 }, // this part line is needed only for second part of answer
temporary: Boolean,
maxUses: Number,
inviterId: String,
guildId: String
created: String,
expiresTimestamp: String || null,
})
on booting up you would have to load up all of those invites that were created while bot was offline
so in ready event
next event would be guildMemberAdd event
to update the entry with new value for Uses
don't just add one, as there could be joins when the bot was offline
If you would like to make it so the number of invites is decreased as members leave the server
The example simple memberSchema where you would store code of invite, guild where the invite is from and memberId
const memberSchema = new Schema({
code: String,
guildId: String,
memberId: String,
})
in here you would be using guildMemberRemove
though the tiny problem in here would be that the number of invites would not be decreased when the bot is offline
to "fix" this you would have to loop thru all elements of memberSchema checking if the person is in there or not
and then update the entry in inviteSchema