Discord.js生成一个Channel Invite



因此,我正试图生成一个不和谐的通道邀请,我的机器人将其发送给只有用户才能使用的用户,因此只能一次性使用。但我不明白,我需要一些帮助。

这是我的代码:

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();
const prefix = '&';
bot.once('ready', () => {
console.log('I am awake');
});
bot.on('message', message => { 
if(!message.content.startsWith(prefix) || message.author.bot) 
return;

const args = message.content.slice(prefix.length).split(' ');
const command = args.shift().toLowerCase();
const replyWithInvite = async (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.author.send(invite ? `Here's your invite: ${invite}` : "There has been an error during the creation of the invite.");
}
if (command === 'invite') {

replyWithInvite(message);
}
});
bot.login('<Your-Login-Token>');

在我的情况下,我使用前缀"&"邀请";,但你可以根据自己的意愿改变。


不和。py:

这个线程可能有帮助吗?

https://stackoverflow.com/a/65770179/14476782

您可以使用<message>.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

相关内容

最新更新