izy521 / discord.io

A small, single-file library for creating DiscordApp clients from Node.js or the browser
https://discord.gg/0MvHMfHcTKVVmIGP
MIT License
535 stars 155 forks source link

TypeError: Cannot read property '18647709XXXXXXX' of undefined #320

Closed FsxShader2012 closed 4 years ago

FsxShader2012 commented 4 years ago

bot.members[userID].voice_channel_id results in the following output TypeError: Cannot read property '18647709XXXXXXX' of undefined (X'ed my UserID for privacy reasons) Same result for every property of the Member object.

bot.users[userID].id works fine.

abdatta commented 4 years ago

Because bot, which a client object, does not have a members property. Even the docs don't mention that it should have. You can get the members property on a server object though. You can use something like this to get the members of a server from a channel ID:

const serverID = bot.channels[channelID].guild_id;
const server = bot.servers[serverID];
// Now you can use members on server to get voice_channel_id
const userVoiceChannelID = server.members[userID].voice_channel_id;
FsxShader2012 commented 4 years ago

Sorry, I'm completely new to OOP. Appreciate the help, works perfectly!

cloudrac3r commented 4 years ago

If you have more questions, please join the server! https://discord.gg/0MvHMfHcTKVVmIGP