在guildCreate

时间:2020-08-12 05:16:45

标签: javascript node.js discord discord.js

我正在尝试创建一个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}`);

        })
});

1 个答案:

答案 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}`);
    });
});