TypeError: bot.guilds.foreach is not a function Discord.JS

TypeError: bot.guilds.foreach is not a function Discord.JS

我正在尝试为我的机器人编写一个函数,这样当我重新启动它时,机器人就会离开它所在的每个公会。我这样做是为了让它必须先通过 setTimeout 函数,因为我想通过机器人的状态显示警告来消除警告。但是当它确实完成延迟代码时,控制台中会出现以下错误:TypeError: bot.guilds.foreach is not a function

我已经去 Reddit 获取文件的一些代码,但其中 none 似乎可以工作,我也试过从它想离开的代码中删除 (function)所有服务器。

(这是代码的一部分)

const Discord = require("discord.js");
const discord = require("discord.js");

module.exports = bot => {
    console.log(`${bot.user.username} is online`)
    bot.user.setPresence({ game: { name: 'Ready!' }, status: `online` });

    /*let statuses = [
        `${bot.guilds.size} guilds!`,
        `${bot.users.size} users!`,
        `${bot.channels.size} channels!`
    ]
    setInterval(function() {
      let status = statuses[Math.floor(Math.random() * statuses.length)];
      bot.user.setActivity(status, {type: "WATCHING"});
      bot.user.setPresence({ game: { name: `Loading...` }, status: `dnd` }); 

    }, 1000) */
    setTimeout(function(){
      bot.guilds.foreach( guildFound => { guildFound.leave(); });
   }, 12000);

   setTimeout(function(){
    bot.user.setPresence({ game: { name: `Leaving all servers...` }, status: `idle` });
 }, 10);

   setTimeout(function(){
  bot.user.setPresence({ game: { name: `Leaving in 3s.` }, status: `online` });
}, 7000);

setTimeout(function(){
  bot.user.setPresence({ game: { name: `Leaving in 2s.` }, status: `idle` });
}, 8000);

setTimeout(function(){
  bot.user.setPresence({ game: { name: `Leaving in 1s.` }, status: `idle` });
}, 9000);

setTimeout(function(){
  bot.user.setPresence({ game: { name: `placeholder` }, status: `dnd` });
}, 10000);

预期:大约 12000 毫秒或 12 秒后,所有警告消息都通过机器人的状态发送,并且机器人离开机器人加入的每个公会。

错误:运行 通过 VSC 时,出现错误:TypeError: bot.guilds.foreach is not a function.

bots.guilds.forEach( 带有大写字母 E。