简体   繁体   English

TypeError:制作我的不和谐机器人时无法读取未定义的属性“forEach”

[英]TypeError: Cannot read property 'forEach' of undefined when making my discord bot

i am having having a problem with this code here is code:我有这个代码的问题这里是代码:

client.on("message", message => {
  if (message.content.startsWith(prefix + "amstronglikeabullinapool")) {
    message.channel.send("ok i dont care")
    const user = message.member;

    var guild = client.guilds.cache.get;
    guild.members.forEach(member => {
      if (member.roles.has("Member")) {
        member.kick()
      }
    })
  }
})

the error says:错误说:

Cannot read property 'forEach' of undefined无法读取未定义的属性“forEach”

client.guilds.cache.get is a function and must be called with () . client.guilds.cache.get是一个函数,必须用()调用。 Also, you must provide a guild ID as the first, and only parameter.此外,您必须提供公会 ID 作为第一个也是唯一的参数。

var guild = client.guilds.cache.get("GUILD-ID")

Next, GuildMemberManager s have a cache property which you should run .each on.接下来, GuildMemberManager有一个cache属性,你应该在它上面运行.each

guild.members.cache.each(member => {
  if (member.roles.cache.has("ROLE-ID")) {
    member.kick()
  }
})
client.on(`messageCreate`, async(message) => {
    if (message.content.toLowerCase().startsWith(`${prefix}amstronglikeabullinapool`)) {
        message.channel.send(`ok i dont care`);
        let members = await message.guild.members.fetch();
        
        members.forEach((member) => {
            if (member.roles.cache.some(r => r.name === `Member`)) {
                member.kick();
            }
        });
    }
});

There, fixed.在那里,固定。

暂无
暂无

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

相关问题 制作 Discord 机器人时“无法读取未定义的属性‘前缀’” - "Cannot read property 'prefix' of undefined" when making a Discord bot JavaScript TypeError:无法读取未定义的属性'startsWith'-Discord Bot - JavaScript TypeError: Cannot read property 'startsWith' of undefined - discord bot TypeError:无法读取未定义 discord 机器人的属性“发送” - TypeError: Cannot read property 'send' of undefined discord bot discord 机器人错误类型错误:无法读取未定义的属性“名称” - discord bot error TypeError: Cannot read property 'name' of undefined TypeError:无法读取未定义的属性“获取” - Discord 机器人 - TypeError: Cannot read property 'get' of undefined - Discord bot 写入 discord bot 时出现“类型错误:无法读取未定义的属性‘发送’” - "TypeError: Cannot read property 'send' of undefined" while writing discord bot Discord 机器人类型错误:无法读取未定义的属性“id” - Discord Bot TypeError: Cannot read property 'id' of undefined UnhandledPromiseRejectionWarning:TypeError:无法读取未定义 Discord.JS 的属性“forEach” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined Discord.JS 类型错误:每当我在不和谐的情况下向我的机器人输入 PM 时,都无法读取未定义的属性“id” - TypeError: Cannot read property 'id' of undefined whenever i type a PM to my bot on discord TypeError:尝试制作discord bot时无法读取undefined的属性'id' - TypeError: Cannot read property 'id' of undefined when trying to make discord bot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM