如何修复discord.js v12中的成员数

如何修复discord.js v12中的成员数,discord,discord.js,Discord,Discord.js,我正在尝试获取会员人数,但我一直收到一个错误,我不知道现在该怎么办 这是我的密码: bot.on('ready',() =>{ let myGuild = bot.guilds.fetch('759858083718496266'); // Discord server ID let memberCount = myGuild.memberCount; let memberCountChannel = channel.messages.cache.get('123

我正在尝试获取会员人数,但我一直收到一个错误,我不知道现在该怎么办

这是我的密码:

bot.on('ready',() =>{ 
    let myGuild = bot.guilds.fetch('759858083718496266'); // Discord server ID
    let memberCount = myGuild.memberCount;
    let memberCountChannel = channel.messages.cache.get('123456789012345678');; // kanalens ID
    memberCountChannel.setName('
.fetch()
does not return a value, it returns a
Promise
. You are trying to treat
myGuild
as if it is a
Guild
object, when in reality it is a
Promise
that is "promising" you a
Guild
object. So how do you obtain the
Guild
object? There are two methods: Promises have a
.then(value => {})
function which you could use, or you could use the simpler
async/await
method.

So here's how that would look in your
ready
event:

bot.on("ready", async () => {

    let myGuild = await bot.guilds.fetch('759858083718496266'); // Discord server ID
    let memberCount = myGuild.memberCount;
    let memberCountChannel = await myGuild.channels.fetch('123456789012345678');

    //rest of your code

});
bot.on('ready',()=>{
让myGuild=bot.guilds.fetch('759858083718496266');//不协调服务器ID
让memberCount=myGuild.memberCount;
让memberCountChannel=channel.messages.cache.get('1234567890121345678');//假名ID
memberCountChannel.setName('
.fetch()
不返回值,它返回一个
Promise
。您试图将
myGuild
视为一个
Guild
对象,而实际上它是一个“有希望”的
Promise
你有一个
Guild
对象。那么如何获得
Guild
对象呢?有两种方法:承诺有一个
。然后(value=>{})
函数可以使用,或者你可以使用更简单的
async/await
方法

下面是您的
ready
事件中的情况:

只需在函数声明之前添加
async
,并在每个
.fetch()
之前添加
wait
。您需要在每个事件处理程序中执行此操作;以上只是
ready
事件处理程序中的一个示例