message.client.guilds.fetch() is not a function

Viewed 6957

Here's the relevant snippet of the code I was working on:

message.client.guilds.fetch('ID Here', false).then(guild => message.channel.send(guild.name))

According do the discord.js docs, this function, GuildManager#fetch(), should theoretically work. However, I keep getting this error:

message.client.guilds.fetch is not a function

I even tried directly copying and pasting the example from the function docs, but it still gave me the same error.

Docs Example

I'm fairly stumped, any help would be appreciated!

Edit: I should mention that all other discord.js fetch methods are working fine, such as:

message.channel.messages.fetch()

Edit #2: My previous problem has been solved, I was using the wrong version of discord.js. However, I now get a new error:

DiscordAPIError: Missing Access

When running it.

1 Answers

You are most likely using an outdated discord.js version. client.guilds was made a GuildManager as of v12.0.0 and the method client.guilds.fetch was added only in the latest version v12.3.0. You need to have a discord.js version >= 12.3.0 in order to use this method.

Try npm ls discord.js to check the active version in your dependencies.
Try npm i discord.js@latest to forcefully upgrade to latest version.

Related