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 Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
duck
duckā€¢16mo 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)
#[derive(ApEnrl)]
#[derive(ApEnrl)]ā€¢16mo ago
Ohh Soo How can i get member from guild?
d.js docs
d.js docsā€¢16mo ago
method GuildMemberManager#fetch() Fetches member(s) from Discord, even if they're offline.
#[derive(ApEnrl)]
#[derive(ApEnrl)]ā€¢16mo ago
But guild.members It's always return null
duck
duckā€¢16mo ago
at no point should guild.members be null care to share your updated code?
#[derive(ApEnrl)]
#[derive(ApEnrl)]ā€¢16mo ago
const guild = client.guilds.fetch("###");
console.log(guild.members)
const guild = client.guilds.fetch("###");
console.log(guild.members)
duck
duckā€¢16mo ago
please reread this message
#[derive(ApEnrl)]
#[derive(ApEnrl)]ā€¢16mo ago
Yeah That's return the same error
duck
duckā€¢16mo ago
care to share your updated code for that?
#[derive(ApEnrl)]
#[derive(ApEnrl)]ā€¢16mo ago
const guild = client.guilds.cache.get("##");
console.log(guild.members)
const guild = client.guilds.cache.get("##");
console.log(guild.members)
duck
duckā€¢16mo ago
do you have the Guilds intent? are you sure your guild id is correct?
#[derive(ApEnrl)]
#[derive(ApEnrl)]ā€¢16mo 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
duckā€¢16mo ago
then where is this executing? is it in an event?
Syjalo
Syjaloā€¢16mo ago
console.log(guild.constructor.name)
#[derive(ApEnrl)]
#[derive(ApEnrl)]ā€¢16mo ago
I ran it on express server But when I log the client it's work very well like console.log(client)
duck
duckā€¢16mo 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
#[derive(ApEnrl)]
#[derive(ApEnrl)]ā€¢16mo 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 Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
#[derive(ApEnrl)]
#[derive(ApEnrl)]ā€¢16mo ago
thank u for your idea šŸ™‚
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docsā€¢16mo 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.
#[derive(ApEnrl)]
#[derive(ApEnrl)]ā€¢16mo ago
My thread was fire Lol
Unknown User
Unknown Userā€¢16mo ago
Message Not Public
Sign In & Join Server To View
#[derive(ApEnrl)]
#[derive(ApEnrl)]ā€¢16mo ago
I don't know javascript very well so what's different with promise and await?
d.js docs
d.js docsā€¢16mo ago
Resources to understand Promise: ā€¢ MDN: learn more ā€¢ Guide: learn more ā€¢ JavaScript info: learn more