Entonces, estoy tratando de crear un tipo de comando que generará 1 uso único en el servidor 1. Ahora, si tuviera que ingresar este comando en un texto general en el servidor 2, !dminvite @user , enviaría al usuario mencionado el único creado invite desde el servidor 1 y envíelo al usuario mencionado en el servidor 2, a través de DM.
Algunas notas:
1. Tengo los 2 ID de servidor guardados en mi archivo config.json y este comando de invitación requiere config.json. En esta base de archivos de comandos
2. Este comando se ejecuta en discord.js v12, pero si alguien quiere ayudar en discord.js v13, también sería increíble.
3. No tengo forma de intentar publicitar nada, soy dueño de ambos servidores.
Tengo un código escrito pero no funciona, solo un punto de vista:
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') ); });Para lograr su objetivo hacemos esto:
systemChannel ). // 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}` } }); } }); Tenga en cuenta que si no desea utilizar systemChannel , simplemente puede obtener cualquier canal que desee del otherGuild por su id, por ejemplo.
// Resolve channel id into a Channel object const channel = otherGuild.channels.resolve("channel id"); Usando discord.js ^12.5.3 .