Javascript 如何编写机器人将发出临时即时邀请的代码?
我试图让我的机器人为它目前所在的公会创建一个临时即时邀请。可能吗?(此bot将是公开的,因此它将出现在许多公会中)Javascript 如何编写机器人将发出临时即时邀请的代码?,javascript,bots,discord.js,Javascript,Bots,Discord.js,我试图让我的机器人为它目前所在的公会创建一个临时即时邀请。可能吗?(此bot将是公开的,因此它将出现在许多公会中) 如果是这样,我请求帮助你可以使用。下面是一个例子: // 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
如果是这样,我请求帮助你可以使用。下面是一个例子:
// 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.");
}
您可以通过添加参数来更改频道。请注意,只有当bot拥有创建邀请的权限时,此操作才有效。您可以使用。下面是一个例子:
// 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.");
}
您可以通过添加参数来更改频道。请注意,只有当机器人拥有创建邀请的权限时,此操作才有效。非常感谢。再一次,我真的很抱歉,因为现在它看起来很简单,但我还在学习,谢谢你的帮助不要担心:)我建议你使用中的搜索栏:它可以帮助你快速找到你需要的方法;)非常感谢你。再一次,我真的很抱歉,因为现在它看起来很简单,但我还在学习,谢谢你的帮助不要担心:)我建议你使用中的搜索栏:它可以帮助你快速找到你需要的方法;)