【问题标题】:TypeError: bot.guilds.foreach is not a function Discord.JSTypeError: bot.guilds.foreach 不是 Discord.JS 函数
【发布时间】:2019-08-30 06:18:49
【问题描述】:

我正在尝试为我的机器人编写一个函数,所以当我重新启动它时,机器人会离开它所在的每个公会。我让它必须首先通过一个 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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-06-15
      • 2022-07-22
      • 2023-01-05
      • 2018-08-11
      • 2020-12-31
      • 2020-12-07
      • 2020-08-23
      • 2020-01-22
      • 2020-11-13
      相关资源
      最近更新 更多