I have a bot system that requires going through an array of users to contact them for an upcoming event, and having an issue trying to recurse through each array in this object.
The array is
var users=bot.servers[bot.serverFromChannel(data['channelid'])].members;
console.log("wee"+util.inspect(users, {showHidden: false, depth: null}))
bot.sendMessage({
to: data['channelid'],
message: "Hello World",
}, function(response) {
console.log("Alright"+users.length)
for (var i = 0, len = users.length; i < len; i++) {
bot.editMessage({
channel: data['channelid'],
messageID: response.id,
message: "Hello <@"+users[i].user.id+">"
});
console.log("wee"+util.inspect(users[i], {showHidden: false, depth: null}))
};
/*bot.deleteMessage({
channel: data['channelid'],
messageID: response.id
});*/
});
So far it goes through, posting the array table and posting 'Hello World', but stops at Alright with undefined.
The array table is like this
{
"domain": null,
"_events": {},
"_eventsCount": 6,
"connected": true,
"servers": {
"923946464": {
"voice_states": [],
"roles": {
"92394097364": {
"position": -1,
"permissions": 369089,
"name": "@everyone",
"managed": false,
"id": "92394464",
"hoist": false,
"color": 0
}
},
"region": "us-east",
"presences": [
],
"owner_id": "9236892256",
"name": "Group",
"members": {
"92368969305952256": {
"user": {
"username": "Nickoplier",
"id": "9256",
"discriminator": "6",
"avatar": "b37f9a293e509"
},
"roles": [],
"mute": false,
"joined_at": "2000-01-01T01:01:09.497000+00:00",
"deaf": false,
"status": "online",
"game_id": null
},
}
}
}
}
userswith the correct data?data['channelid']is actually "923946464" because I suspect that users isundefinedbecause you're getting.memberson an object without that property.