今天,我在运行机器人时遇到了一个错误,我试图实现监视#
的 fancy 活动。但是我遇到了一些问题
代码如下:
const client = new Discord.Client();
const { token, prefix} = require('./config.json');
const infernoGuild = client.guilds.resolve('724848757589409854')
const guildMemberCount = infernoGuild.memberCount;
client.on('ready', () => {
client.user.setActivity(`over ${guildMemberCount}`, {type: 'WATCHING'})
.then(presence => console.log(`Activity set to ${presence.activities[0].name}`))
.catch(console.error);
})
client.on('ready', async message => {
let args
})
client.login(token)
这是错误:
TypeError: Cannot read property 'memberCount' of null
at Object.<anonymous> (/Users/sameerabdullah/Desktop/yousef/InfernoAPI/server.js:7:39)
at Module._compile (internal/modules/cjs/loader.js:774:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
at Module.load (internal/modules/cjs/loader.js:641:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
at internal/main/run_main_module.js:17:11
我在互联网上找不到任何答案
对不起,我的英语不好
答案 0 :(得分:2)
const infernoGuild = client.guilds.cache.get("724848757589409854");
if (!infernoGuild) return console.error(`The Guild ID is invalid.`);
client.on("ready", () => {
client.user.setActivity(`over ${infernoGuild.memberCount}`, {type: "WATCHING"});
});
答案 1 :(得分:0)
使用:const infernoGuild = client.guilds.cache.get('724848757589409854')