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

问题描述 投票:0回答:1

我正在尝试为我的机器人编写一个函数,所以当我重新启动它时,僵尸程序会离开它所在的每一个公会。我这样做是为了让它必须首先通过一个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个回答
1
投票

它的bots.guilds.forEach(与首都E.

© www.soinside.com 2019 - 2024. All rights reserved.