在guildCreate

问题描述

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

        })
});

解决方法

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...