问题
I have a site where users register. In the registration process, I ask them to provide their discord user to let them access a discord community we own.
Is it possible to create an invite for my guild/channel and send it to a discord user using discord.js? I need this invite to be unique and limited to one use. So, I need to create a new one everytime a user registers at the site.
回答1:
It is possible to create a unique invite, but you cannot send it to the user inside Discord, you'll need to show the link in your webpage: bots cannot message users that are not in a mutual guild, to prevent spamming.
To create an invite you can use the GuildChannel.createInvite() method:
let newInvite = await channel.createInvite({
maxUses: 1, // After one use it will be void
unique: true, // That tells the bot not to use an existing invite so that this will be unique
maxAge: 86400 // By default invites last 24 hours. If you want to change that, modify this (0 = lasts forever, time in seconds)
});
来源:https://stackoverflow.com/questions/54463473/creating-an-invite-and-send-it-to-an-user-that-is-not-in-your-server-guild