Reputation: 607
I need the bot to get the guild ID on join for an api. At the moment I've tried this, but I get an error:
Cannot read property 'id' of undefined
My code
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);
}
);
});
Upvotes: 1
Views: 1087
Reputation: 710
Your issue is that you try to get guild.id
and guild.memberCount
from client
.
guildCreate callback parameter returns the Guild joined, so modify as following :
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);
}
);
});
Upvotes: 3