我正在尝试创建一个Discord机器人,该机器人将在添加到上述公会中并将其发送到控制台时创建对公会第一个频道的邀请。
我的代码(不起作用):
client.on("guildCreate", guild => {
const channel = Array.from(guild.channels).sort((a, b) => a.calculatedPosition - b.calculatedPosition)[0];
channel.createInvite({
unique: true
})
.then(invite => {
console.log(`Joined to: ${guild.name} Invite: https://discord.gg/${invite.code}`);
})
});
答案 0 :(得分:0)
// Listeing to the guildCreate event.
client.on("guildCreate", guild => {
// Filtering the channels to get only the text channels.
const Channels = guild.channels.cache.filter(channel => channel.type == "text");
// Creating an invite.
Channels.first().createInvite({
maxUses: 1,
unique: true
}).then(invite => {
console.log(`[INVITE] I've created an invite for ${guild.id}:${guild.name} - ${invite.url}`);
});
});