我需要机器人在加入api时获得行会ID。目前,我已尝试过此操作,但出现错误:
Cannot read property 'id' of undefined
我的代码
client.on("guildCreate", (guild) => {
request(
{
url:
"https://urlgoeshere" +
client.guild.id +
"/" +
key +
"/" +
client.guild.memberCount,
},
function (error, httpResponse, body) {
console.error("error:", error);
console.log("body:", body);
}
);
});
答案 0 :(得分:3)
您的问题是您尝试从guild.id
获取guild.memberCount
和client
。
guildCreate回调参数返回加入的Guild,因此请进行以下修改:
client.on("guildCreate", (guild) => {
request(
{
url:
"https://urlgoeshere" +
guild.id +
"/" +
key +
"/" +
guild.memberCount,
},
function (error, httpResponse, body) {
console.error("error:", error);
console.log("body:", body);
}
);
});