简体   繁体   English

message.client.guilds.fetch() 不是函数

[英]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.据做discord.js文档,这个功能, GuildManager#fetch()理论上应该工作。 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:编辑:我应该提到所有其他discord.js fetch方法都可以正常工作,例如:

message.channel.messages.fetch()

Edit #2: My previous problem has been solved, I was using the wrong version of discord.js .编辑#2:我之前的问题已经解决,我使用了错误版本的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.您很可能使用过时的discord.js版本。 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. client.guilds被做了GuildManager为v12.0.0和方法client.guilds.fetch只在最新版本v12.3.0加入。 You need to have a discord.js version >= 12.3.0 in order to use this method.你需要有一个discord.js为了使用这种方法的版本> = 12.3.0。

Try npm ls discord.js to check the active version in your dependencies.尝试使用npm ls discord.js检查依赖项中的活动版本。
Try npm i discord.js@latest to forcefully upgrade to latest version.尝试npm i discord.js@latest强制升级到最新版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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