TypeError:无法读取未定义的属性(读取'成员')Discord JS

发布于 2025-02-06 14:10:32 字数 315 浏览 4 评论 0原文

在我的机器人中,我不断遇到一个错误,因为它看不到参与者

const client = new Discord.Client({
    intents: new Discord.Intents(32767)
})
const guild = client.guilds.cache.get('909512069999628349'); 

client.on('ready', () =>   
{
    guild.members.fetch()
    .then(console.log)
    .catch(console.error);
});

In my bot, I constantly get an error that it does not see participants

const client = new Discord.Client({
    intents: new Discord.Intents(32767)
})
const guild = client.guilds.cache.get('909512069999628349'); 

client.on('ready', () =>   
{
    guild.members.fetch()
    .then(console.log)
    .catch(console.error);
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉生梦死 2025-02-13 14:10:32

在试图获取行会之前,您的机器人没有登录不和谐。很简单。只需将const guild移入就绪事件中,或使用与此类似的黑客:

let guild;
client.on('ready', () => {
  guild = client.guilds.cache.get('id')

Your bot is not being logged into Discord before the guild is attempted to be fetched. It's simple. Just move the const guild inside the Ready event, or use a hack similar to this:

let guild;
client.on('ready', () => {
  guild = client.guilds.cache.get('id')
二手情话 2025-02-13 14:10:32

尝试使用成员?.fetch(),您的对象可能不确定

Try using members?.fetch(), probably your object might be undefined so do this instead

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文