Javascript Discord.js生成频道邀请
所以我试图生成一个不和谐频道邀请,我的机器人发送给一个只有他才能使用的用户,所以是一次性使用。但我不明白,我需要一些帮助 这是我的代码:Javascript Discord.js生成频道邀请,javascript,Javascript,所以我试图生成一个不和谐频道邀请,我的机器人发送给一个只有他才能使用的用户,所以是一次性使用。但我不明白,我需要一些帮助 这是我的代码: if (reaction.emoji.name === '1️⃣') { await reaction.message.guild.members.cache.get( user.id); if(array.length >= 1){ if(message.member.roles.cache.has('5297706589
if (reaction.emoji.name === '1️⃣') {
await reaction.message.guild.members.cache.get(
user.id);
if(array.length >= 1){
if(message.member.roles.cache.has('529770658914369537')){
const channel = client.channels.cache.find(channel => channel.name === 'Gaming Lounge')
let invite = channel.createInvite({
maxAge: 0,
maxUses: 1
}).catch(console.error);
console.log(`Here is your Invite: ${invite}`);
client.users.cache.get(array[0]).send(
`Here is your Invite: ${invite}`);
array.splice(0, 1);
console.log(array);
reaction.users.remove(user);
}
}
}
discord.js:
const discord=require('discord.js');
const bot=new discord.Client();
常量前缀='&';
bot.one('ready',()=>{
console.log(“我醒着”);
});
在('message',message=>{
if(!message.content.startsWith(前缀)| | message.author.bot)
返回;
const args=message.content.slice(前缀.length).split(“”);
const命令=args.shift().toLowerCase();
const replyWithInvite=异步(消息)=>{
let invite=等待message.channel.createInvite(
{
maxAge:10*60*1000,//邀请的最长时间,以毫秒为单位
最大使用次数:1//可使用的最大次数
},
`${message.author.tag}使用命令请求`
)
.catch(console.log);
message.author.send(invite?`这是您的invite:${invite}`:“在创建invite的过程中出现错误。”);
}
如果(命令=='invite'){
回复WITHINVITE(消息);
}
});
bot.login(“”);
在我的例子中,我使用前缀“&invite”,但您可以根据自己的需要进行更改
discord.py: 这条线可能有用吗 您可以使用
.channel.createInvite()
方法
const channel = client.channels.cache.find(channel => channel.name === 'Gaming Lounge')
const channelInvite = await channel.createInvite({ maxAge: 60000, maxUses: 1 }).catch(e => console.log(e));
message.author.send(channelInvite ? channelInvite : 'Oops something went wrong').catch(e => console.log(e)); // incase the user dms are blocked
你面临什么问题?你需要比“不明白”更具体我不知道如何生成一个不和谐的邀请,所以我需要一个用户可以使用一次的邀请链接,这就是如果我使用上面的代码,我收到这个消息:这是你的邀请:[对象承诺]你缺少了一个
wait
好的,我会试试看它是否有效确定它可以发送不和谐的邀请,但Maxuse不起作用,所以我将邀请发送给了两个人,对所有人都有效。但我需要它只工作一次,然后邀请应该是无效的