如何编码该机器人将发出临时即时邀请?

Sil*_*her 0 javascript bots discord.js

我正在尝试让我的机器人为其当前所在的公会创建临时即时邀请。这可能吗?(这个机器人将是公开的,所以它会在很多公会中)
如果是这样,我正在寻求帮助 <3
(对不起,如果这很容易编码。我还在学习 js ;D)

Fed*_*ndi 5

您可以使用GuildChannel.createInvite(). 下面是一个例子:

// ASSUMPTIONS:
// message is the message that triggered the command
// the channel of the invite will be the channel where the message has been sent

async function replyWithInvite(message) {
  let invite = await message.channel.createInvite(
  {
    maxAge: 10 * 60 * 1000, // maximum time for the invite, in milliseconds
    maxUses: 1 // maximum times it can be used
  },
  `Requested with command by ${message.author.tag}`
)
.catch(console.log);

  message.reply(invite ? `Here's your invite: ${invite}` : "There has been an error during the creation of the invite.");
}
Run Code Online (Sandbox Code Playgroud)

您可以通过添加参数来更改频道。请注意,这仅在机器人有权创建邀请时才有效。