Creating an invite and send it to an user that is not in your server/guild

寵の児 提交于 2021-02-05 09:04:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!