Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

79
Views
Create invite from server 1 and send to user DMS in server 2

So I am trying to create a type of command that will generate 1 single use in server 1. Now if I were to input this command into a general text in server 2, !dminvite @user, it would send the mentioned user the single created invite from server 1 and send it to the mentioned user in server 2, via DMs.

Some Notes:

1. I have the 2 server id's saved in my config.json file and this invite command requires config.json. In this commands file base

2. This command is running over discord.js v12, but if anyone wants to help out in discord.js v13, It would be amazing as well.

3. I am no way in trying to advertise anything, I own both servers

I have a code written down but it's not working, just a view point:

message.delete();

message.mentions.members.first() ||
message.guild.members.cache.get(args[0]);

const Options = {
    temporary: false,
    maxAge: 0,
    maxUses: 1,
    unique: true
};

const channel = message.guild.channels.cache.get('(Channel ID)');

let invite = message.channels.createInvite(Options).then(function(Invite) {
    message.mentions.members.first().send({embed: {
        title: `**INVITE**`,
        description: `Invite:\nhttps://discord.gg/` + Invite.code
    }});
    message.channel.send(new Discord.MessageEmbed()
        .setAuthor(message.author.tag, message.author.displayAvatarURL({ dynamic: true }))
        .setDescription(`${message.author.tag}, invite was sent to DMs`)
        .setColor('BLUE')
    );
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To accomplish your goal we do this:

  1. Get the mentioned user from the message.
  2. Fetch the other guild we want to invite the user to.
  3. Create an invite to the other guild's system channel (it doesn't have to be systemChannel).
  4. Send the invite to the mentioned user's DMs.
// Id of the other guild
const otherGuildId = "guild id";

client.on("message", async (message) => {

    // Don't reply to itself
    if (message.author.id == client.user.id) return;

    // Check if the message starts with our command
    if (message.content.startsWith("!dminvite")) {

        // Get the mentioned user from the message
        const user = message.mentions.users.first();
        if (!user) {
            message.channel.send("You need to mention the user to send the invitation to.");
            return;
        }
    
        // Fetch the other guild we want to invite the user to
        const otherGuild = await client.guilds.fetch(otherGuildId);
        // Create invite to the other guild's system channel
        const invite = await otherGuild.systemChannel.createInvite({
            maxAge: 0,
            maxUses: 1,
            unique: true
        });
    
        // Send the invite to the mentioned user's DMs
        user.send({
            embed: {
                title: "**INVITE**",
                description: `${invite}`
            }
        });

    }

});

Note that if you don't want to use the systemChannel, you can simply get any channel you want from the otherGuild by its id for example.

// Resolve channel id into a Channel object
const channel = otherGuild.channels.resolve("channel id");

Using discord.js ^12.5.3.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!