Discord.js: client.guilds.fetch throwing an error regarding a missing shard

Created on 8 Oct 2020  Â·  3Comments  Â·  Source: discordjs/discord.js

I am running into an issue trying to fetch a list of all users in a Server (Guild)

Just set up a new simple Discord Bot and installed the latest Discord.js in a new project. I'm just trying to fetch a list of all users in a Server (guild):

const Discord = require('discord.js')

const client = new Discord.Client()
client.login(process.env.DISCORD_BOT_TOKEN)

const server = await client.guilds.fetch(process.env.DISCORD_SERVER_ID)
const members = await server.members.fetch()

Results in an error message of:

Cannot read property 'send' of undefined

Referencing src/managers/GuildMemberManager.js:276:24, which is calling

this.guild.shard.send

And of course this.guild.shard is undefined.

Further details:

  • discord.js version: 12.3.1
  • Node.js version: v12.16.3
  • Operating system: MacOS Catalina 10.15.7
  • Priority this issue should have – we're working on building a Discord bot for a paying client using Discord.js so I can code around this issue a little but will prevent any meaningful progress
invalid

Most helpful comment

These operations need to be executed after the client has logged in. To ensure this place the code in any client event callback as any boilerplate or guide suggests. If you want to do this regardless of message context the Client event "ready" is available which emits after the client has become fully ready.


If you need help with discord.js installation or usage, please go to the discord.js Discord server instead:
https://discord.gg/bRCvFy9
This issue tracker is only for bug reports and enhancement suggestions. You won't receive any basic help here.

All 3 comments

Any updates on this? I am getting the exact same error

These operations need to be executed after the client has logged in. To ensure this place the code in any client event callback as any boilerplate or guide suggests. If you want to do this regardless of message context the Client event "ready" is available which emits after the client has become fully ready.


If you need help with discord.js installation or usage, please go to the discord.js Discord server instead:
https://discord.gg/bRCvFy9
This issue tracker is only for bug reports and enhancement suggestions. You won't receive any basic help here.

These operations need to be executed after the client has logged in. To ensure this place the code in any client event callback as any boilerplate or guide suggests. If you want to do this regardless of message context the Client event "ready" is available which emits after the client has become fully ready.

If you need help with discord.js installation or usage, please go to the discord.js Discord server instead:
https://discord.gg/bRCvFy9
This issue tracker is only for bug reports and enhancement suggestions. You won't receive any basic help here.

waited for the "ready" event and it worked after. Thank you so much!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kvn1351 picture kvn1351  Â·  3Comments

Lombra picture Lombra  Â·  3Comments

PassTheMayo picture PassTheMayo  Â·  3Comments

DatMayo picture DatMayo  Â·  3Comments

Blumlaut picture Blumlaut  Â·  3Comments