Guild's member by id

const guild = client.guilds.fetch("####");
console.log(guild.members.cache.get(id));
const guild = client.guilds.fetch("####");
console.log(guild.members.cache.get(id));
I can get that guild from id, but When I try to get that member by id, the error has occurred like below TypeError: Cannot read properties of undefined (reading 'cache') at Query.<anonymous> (D:\Project\minecraft\Commission\Illusion\Bot\web\server.js:64:43) at Query.<anonymous> (D:\Project\minecraft\Commission\Illusion\Bot\node_modules\mysql\lib\Connection.js:526:10) at Query._callback (D:\Project\minecraft\Commission\Illusion\Bot\node_modules\mysql\lib\Connection.js:488:16) at Query.Sequence.end (D:\Project\minecraft\Commission\Illusion\Bot\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24) at Query._handleFinalResultPacket (D:\Project\minecraft\Commission\Illusion\Bot\node_modules\mysql\lib\protocol\sequences\Query.js:149:8) at Query.EofPacket (D:\Project\minecraft\Commission\Illusion\Bot\node_modules\mysql\lib\protocol\sequences\Query.js:133:8) at Protocol._parsePacket (D:\Project\minecraft\Commission\Illusion\Bot\node_modules\mysql\lib\protocol\Protocol.js:291:23) at Parser._parsePacket (D:\Project\minecraft\Commission\Illusion\Bot\node_modules\mysql\lib\protocol\Parser.js:433:10) at Parser.write (D:\Project\minecraft\Commission\Illusion\Bot\node_modules\mysql\lib\protocol\Parser.js:43:10) at Protocol.write (D:\Project\minecraft\Commission\Illusion\Bot\node_modules\mysql\lib\protocol\Protocol.js:38:16) So How can I get guild's member by id?
26 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
duck
duck2y ago
fetch is asynchronous, but guilds will always be cached on the assumption you have the Guilds intent, so you can just access client.guilds.cache.get(<ID>) guild members however are not always cached, so you would want to fetch that (this is also asynchronous)
계정 버림
계정 버림OP2y ago
Ohh Soo How can i get member from guild?
d.js docs
d.js docs2y ago
method GuildMemberManager#fetch() Fetches member(s) from Discord, even if they're offline.
계정 버림
계정 버림OP2y ago
But guild.members It's always return null
duck
duck2y ago
at no point should guild.members be null care to share your updated code?
계정 버림
계정 버림OP2y ago
const guild = client.guilds.fetch("###");
console.log(guild.members)
const guild = client.guilds.fetch("###");
console.log(guild.members)
duck
duck2y ago
please reread this message
계정 버림
계정 버림OP2y ago
Yeah That's return the same error
duck
duck2y ago
care to share your updated code for that?
계정 버림
계정 버림OP2y ago
const guild = client.guilds.cache.get("##");
console.log(guild.members)
const guild = client.guilds.cache.get("##");
console.log(guild.members)
duck
duck2y ago
do you have the Guilds intent? are you sure your guild id is correct?
계정 버림
계정 버림OP2y ago
The both is require in "yes"
const client = new Client({
intents:[Guilds,GuildMembers,GuildMessages,GuildInvites],
partials:[User,Message,GuildMember,ThreadMember]
})
const client = new Client({
intents:[Guilds,GuildMembers,GuildMessages,GuildInvites],
partials:[User,Message,GuildMember,ThreadMember]
})
duck
duck2y ago
then where is this executing? is it in an event?
Syjalo
Syjalo2y ago
console.log(guild.constructor.name)
계정 버림
계정 버림OP2y ago
I ran it on express server But when I log the client it's work very well like console.log(client)
duck
duck2y ago
that's not what I'm asking the guild cache is only populated when your bot is logged in, so if you attempt to get a Guild from the cache outside of any client event, it's likely not logged in/ready yet
계정 버림
계정 버림OP2y ago
Still undefined I solved it
let person = client.users.fetch(id);
person.then(function(result1) {
console.log(result1)
});
let person = client.users.fetch(id);
person.then(function(result1) {
console.log(result1)
});
Thank you for everyone 🙂
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
계정 버림
계정 버림OP2y ago
thank u for your idea 🙂
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs2y ago
mdn Promise.prototype.then() The then() method of a Promise object takes up to two arguments: callback functions for the fulfilled and rejected cases of the Promise. It immediately returns an equivalent Promise object, allowing you to chain calls to other promise methods.
계정 버림
계정 버림OP2y ago
My thread was fire Lol
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
계정 버림
계정 버림OP2y ago
I don't know javascript very well so what's different with promise and await?
d.js docs
d.js docs2y ago
Resources to understand Promise: • MDN: learn more • Guide: learn more • JavaScript info: learn more
Want results from more Discord servers?
Add your server