TypeError: Cannot read properties of undefined (reading 'members')

const guild = container.client.guilds.cache.get(event.guild_id);
const member = await guild.members.fetch(event.author.id);
const guild = container.client.guilds.cache.get(event.guild_id);
const member = await guild.members.fetch(event.author.id);
TypeError: Cannot read properties of undefined (reading 'members')
TypeError: Cannot read properties of undefined (reading 'members')
This is inside a Raw event
31 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
d.js docs
d.js docs9mo ago
- The provided id is incorrect (copy role ids from context menus, not message mentions) - The client does not have this structure cached (try fetching instead) - The client is not yet ready (move the code into any event listener callback)
-Carlos👑
-Carlos👑OP9mo ago
const guild = await container.client.guilds.fetch(event.guild_id);
const member = await guild.members.fetch(event.author.id);
const guild = await container.client.guilds.fetch(event.guild_id);
const member = await guild.members.fetch(event.author.id);
TypeError: Cannot read properties of undefined (reading 'fetch')
TypeError: Cannot read properties of undefined (reading 'fetch')
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
-Carlos👑
-Carlos👑OP9mo ago
used fetch instead on the guild variable the id is correct already tried fetching code is in a event listener
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
-Carlos👑
-Carlos👑OP9mo ago
[ERROR] Encountered error on event listener "raw" for event "raw" at path "C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\listeners\raw.js" TypeError: Cannot read properties of undefined (reading 'fetch')
at Raw.run (C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\listeners\raw.js:7:40)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.fromAsync (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@sapphire\result\dist\cjs\index.cjs:619:22)
at async Raw._run (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@sapphire\framework\dist\cjs\lib\structures\Listener.cjs:27:22)
[ERROR] Encountered error on event listener "raw" for event "raw" at path "C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\listeners\raw.js" TypeError: Cannot read properties of undefined (reading 'fetch')
at Raw.run (C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\listeners\raw.js:7:40)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.fromAsync (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@sapphire\result\dist\cjs\index.cjs:619:22)
at async Raw._run (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@sapphire\framework\dist\cjs\lib\structures\Listener.cjs:27:22)
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
-Carlos👑
-Carlos👑OP9mo ago
wdym
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
-Carlos👑
-Carlos👑OP9mo ago
Sapphire needs discord.js to work so yes handling polls
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
-Carlos👑
-Carlos👑OP9mo ago
const member = await guild.members.fetch(event.author.id);
const member = await guild.members.fetch(event.author.id);
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
-Carlos👑
-Carlos👑OP9mo ago
oh sorry
Collection(1) [Map] {
'e' => OAuth2Guild {
id: '',
name: '',
icon: '',
features: [ '', '' ],
owner: '',
permissions: PermissionsBitField { bitfield: 1n }
}
}
Collection(1) [Map] {
'e' => OAuth2Guild {
id: '',
name: '',
icon: '',
features: [ '', '' ],
owner: '',
permissions: PermissionsBitField { bitfield: 1n }
}
}
this is what guild logged i removed some stuff, the log obviously had that information
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
-Carlos👑
-Carlos👑OP9mo ago
i already trying without fetching but i can try again it logged undefined now
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs9mo ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. - Once you do, log relevant values and if-conditions - More sophisticated debugging methods are breakpoints and runtime inspections: learn more
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
-Carlos👑
-Carlos👑OP9mo ago
logged member and this is what it returned
[ERROR] Encountered error on event listener "raw" for event "raw" at path "C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\listeners\raw.js" TypeError: Cannot read properties of undefined (reading 'members')
at Raw.run (C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\listeners\raw.js:9:32)
at C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@sapphire\framework\dist\cjs\lib\structures\Listener.cjs:27:63
at Object.fromAsync (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@sapphire\result\dist\cjs\index.cjs:619:46)
at Raw._run (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@sapphire\framework\dist\cjs\lib\structures\Listener.cjs:27:42)
at Client.emit (node:events:514:28)
at WebSocketManager.<anonymous> (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\discord.js\src\client\websocket\WebSocketManager.js:236:19)
at WebSocketManager.emit (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.onMessage (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@discordjs\ws\dist\index.js:988:14)
[ERROR] Encountered error on event listener "raw" for event "raw" at path "C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\listeners\raw.js" TypeError: Cannot read properties of undefined (reading 'members')
at Raw.run (C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\listeners\raw.js:9:32)
at C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@sapphire\framework\dist\cjs\lib\structures\Listener.cjs:27:63
at Object.fromAsync (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@sapphire\result\dist\cjs\index.cjs:619:46)
at Raw._run (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@sapphire\framework\dist\cjs\lib\structures\Listener.cjs:27:42)
at Client.emit (node:events:514:28)
at WebSocketManager.<anonymous> (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\discord.js\src\client\websocket\WebSocketManager.js:236:19)
at WebSocketManager.emit (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.onMessage (C:\Users\cmart\Desktop\Discord Bots\Sapphire\node_modules\@discordjs\ws\dist\index.js:988:14)
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
-Carlos👑
-Carlos👑OP9mo ago
probably, no idea why
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
-Carlos👑
-Carlos👑OP9mo ago
what are the most common reasons of a guild being undefined
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs9mo ago
- The provided id is incorrect (copy role ids from context menus, not message mentions) - The client does not have this structure cached (try fetching instead) - The client is not yet ready (move the code into any event listener callback)
-Carlos👑
-Carlos👑OP9mo ago
will log ids just incase but i'm sure they are defined
-Carlos👑
-Carlos👑OP9mo ago
tried logging this but it returned an error:
console.log(`Guild ID: ${event.guild_id}\nMember ID: ${event.author.id}`);
console.log(`Guild ID: ${event.guild_id}\nMember ID: ${event.author.id}`);
[ERROR] Encountered error on event listener "raw" for event "raw" at path "C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\listeners\raw.js" TypeError: Cannot read properties of undefined (reading 'id')
[ERROR] Encountered error on event listener "raw" for event "raw" at path "C:\Users\cmart\Desktop\Discord Bots\Sapphire\src\listeners\raw.js" TypeError: Cannot read properties of undefined (reading 'id')
However I also logged event.d, where event.author.id is defined
No description
Squid
Squid9mo ago
If event.d is logging the data with the author, shouldn't you be accessing event.d.author.id instead?
-Carlos👑
-Carlos👑OP9mo ago
you're right, no idea how I didn't realize that ty for the help
Want results from more Discord servers?
Add your server