TypeError:bot.guilds.foreach不是函数Discord.JS

时间:2019-04-09 03:19:40

标签: node.js visual-studio-code discord.js

我正在尝试为我的机器人编写一个函数,所以当我重新启动它时,该机器人会将它留在每个公会中。之所以这样做,是因为它必须首先通过setTimeout函数,因为我想获取通过机器人的状态显示警告。但是,当确实要完成延迟代码时,控制台中会发生以下错误:TypeError: bot.guilds.foreach is not a function

我去了Reddit来获取文件的一些代码,但是它们似乎都不起作用,我还尝试了从要保留所有服务器的代码中删除(函数)。

(这是代码的一部分)

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

1 个答案:

答案 0 :(得分:1)

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