简体   繁体   中英

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

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 thediscord.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.

文档示例

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM