Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

81
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda