How To Make A Invite Tracker Bot With MongoDB With Removeinvites Feature

Viewed 24

I know what to do

I have to use guildMemberAdd and guildMemberRemove Events. In a help server, they said i want to use a database So my choice was mongodb And I Dont Know How To Do

If Someone Can Help Me With Code Snippets It Will be a real help

Any help will be appriciated

Thanks!

1 Answers

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

Related