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')
);
});
To accomplish your goal we do this:
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}`
}
});
}
});
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.