discord-inviter

0.9.3 • Public • Published

Discord-inviter

NPM version NPM downloads NPM downloads

Installation

Install discord-inviter

$ npm install discord-inviter

Install discord.js

$ npm install discord.js

Features

  • Simple & easy to use 🎗️
  • Support vanity urls 🔗
  • Returns full object with invite & inviter data 📡

What's new ?

  • fix some bugs ⛏️
  • You can get inviter guild member (inviter.member) 📢
  • Support discord.js v12 & v13 & v14 ⚙️
  • Now, you can know when the invite is vanity or no (invite.isVanity)

Getting Started

At first install the discord-inviter package

  • the exampls below are for discord.js (v13), you can update to (v14) without any problem (but don't forget to add the required intents).
const { Client, Intents } = require("discord.js"); // npm i discord.js
const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.GUILD_MEMBERS,
    Intents.FLAGS.GUILD_INVITES,
  ],
});

var { inviteTracker } = require("discord-inviter"), // npm i discord-inviter
  tracker = new inviteTracker(client);

client.on("ready", () => console.log("Bot Ready"));

// "guildMemberAdd"  event to get full invite data
tracker.on("guildMemberAdd", async (member, inviter, invite, error) => {
  // return when get error
  if (error) return console.error(error);
  // get the channel
  let channel = member.guild.channels.cache.get("939210311276306455"),
    Msg = `Welcome ${member.user}, invited by <@!${inviter.id}>, code ${invite.code}, invite count ${invite.count}`;
  // change welcome message when the member is bot
  if (member.user.bot)
    Msg = `Welcome ${member.user}, invited by <@!${inviter.id}>`;
  // send welcome message
  channel.send(Msg);
});

// "error" event to get any error
tracker.on("error", (guild, err) => {
  console.error(guild?.name, err);
});

client.on("messageCreate", async (message) => {
  // get member invites count
  if (message.content == "invites") {
    var invite = await inviteTracker.getMemberInvites(message.member);
    message.channel.send(
      `${message.author.tag} has ${invite.count} invite(s).`
    );
    // get server top invites
  } else if (message.content == "top-invites") {
    var top = await inviteTracker.getTopInvites(message.guild);
    message.channel.send(
      top
        .map((i, n) => `\`#${n + 1}\`- **${i.user.tag}** has __${i.count}__`)
        .join("\n")
    );
    // get info of any invite code
  } else if (message.content == "invite-info") {
    var invite = await inviteTracker.getInfo(client, "https://discord.gg/maxSPHjvaw"); // invite url or code
    if (!invite) return;

    message.channel.send(
      `Guild: ${invite.guild.name},\nInviter: ${
        invite?.inviter ? `${invite.inviter.tag}` : "Owner"
      },\nLink: ${invite.url}`
    );
  }
});

Notes:

  • You must use nodeJs version 16 or higher.
  • You need to update your nodeJs version if you use discord.js v12.

for replit

  • Go to shell and type npm i node@16
  • create file named .replit and type run = "npx node index.js"
  • Run the project.

Thanks for using it ❤️. Support

Package Sidebar

Install

npm i discord-inviter

Weekly Downloads

437

Version

0.9.3

License

ISC

Unpacked Size

13.5 kB

Total Files

3

Last publish

Collaborators

  • jamel_syr
  • naimabd
  • iarth