disvite
    Preparing search index...

    disvite

    DisVite

    An advanced Discord invite tracking module with native Mongoose support for Discord.js bots.

    npm version license


    • Tracks all invite joins: Normal, vanity, and unknown joins
    • Persistent storage: MongoDB/Mongoose integration
    • Customizable: Model name, verbose logging, and extensible via subclassing
    • TypeScript & JSDoc support: Full typings and easy integration in JS or TS bots
    • Event-driven: Emits events for joins, leaves, and errors


    npm install disvite
    


    import { Client, GatewayIntentBits } from "discord.js";
    import { InviteTracker } from "disvite";

    const client = new Client({
    intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.GuildInvites,
    ],
    });

    const tracker = new InviteTracker(client, "mongodb://localhost:27017/mydb", {
    modelName: "customInviteModel", // optional
    verbose: true, // optional
    });

    tracker.on("inviteJoin", (member, info) => {
    console.log(`${member.user.tag} joined via:`, info);
    });

    tracker.on("inviteLeave", (member, record) => {
    console.log(`${member.user.tag} left. Record:`, record);
    });

    client.login("YOUR_BOT_TOKEN");
    const { Client, GatewayIntentBits } = require("discord.js");
    const { InviteTracker } = require("disvite");

    const client = new Client({
    intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.GuildInvites,
    ],
    });

    const tracker = new InviteTracker(client, "mongodb://localhost:27017/mydb", {
    verbose: true,
    });

    /**
    * @param {import('discord.js').GuildMember} member
    * @param {import('disvite').InviteInfo} info
    */
    tracker.on("inviteJoin", (member, info) => {
    console.log(`${member.user.tag} joined via:`, info);
    });

    client.login("YOUR_BOT_TOKEN");

    Option Type Default Description
    modelName string "inviteSchema" MongoDB model name for invite records
    verbose boolean false Enable verbose logging

    Pass these as the third argument to the InviteTracker constructor.


    Event Arguments Description
    inviteJoin (member, info) Emitted when a member joins (see InviteInfo)
    inviteLeave (member, record) Emitted when a member leaves
    error (error) Emitted on non-critical or critical errors

    All types are exported as individual types:

    import { InviteInfo } from "disvite";

    // Example:
    const info: InviteInfo = { ... };

    Reference types for IntelliSense:

    /**
    * @param {import('disvite').InviteInfo} info
    */
    function handleInvite(info) { ... }

    Or define a global typedef:

    /**
    * @typedef {import('disvite').InviteInfo} InviteInfo
    */

    • client: Discord.js Client instance
    • mongoURI: MongoDB connection string
    • options: See Options
    Field Type Description
    guildId string Guild/server ID
    inviteeId string User who joined
    inviterId string | null User who created the invite
    inviteCode string | null Invite code used
    joinType "normal" | "vanity" | "unknown" Type of join
    fake boolean Whether the join is detected as fake
    joinedAt Date When the user joined

    You can extend InviteTracker and override protected methods for custom logic.

    class MyTracker extends InviteTracker {
    protected async detectFakeInvite(member) {
    // Custom logic
    return false;
    }
    }

    Q: My bot isn't tracking invites correctly!
    A: Ensure your bot has the GUILD_MEMBERS and GUILD_INVITES intents enabled and the correct permissions.

    Q: How do I use the types in JavaScript?
    A: Use JSDoc with import('disvite').<Type>.

    Q: How do I change the MongoDB model name?
    A: Pass modelName: "yourModelName" in the options object.

    Q: How do I disable verbose logging?
    A: Pass verbose: false in the options object.


    Pull requests and issues are welcome!
    Please open an issue for bugs, feature requests, or questions.


    GPL-3.0: See LICENSE for more info.


    See Releases for version history.


    Enjoy using DisVite!