首页 > 解决方案 > guild.channels.cache.array() 返回一个空数组。与 client.channels.cache.array() 相同

问题描述

此代码返回一个空数组 -[]为什么?公会有很多频道。

'use strict'

import { Client } from 'discord.js'

const bot = new Client

bot.login('token')

bot.guilds.fetch('826581310151196712').then(server => {
  console.log(server.channels.cache.array())
})

标签: javascriptnode.jsdiscorddiscord.js

解决方案


我认为您需要遍历数组或传播它。

bot.guilds.fetch('826581310151196712')
  .then({ channels : { cache : { array } } } => {
    for (const channel of array()) {
      console.log(channel.id);
    }
  })

也许你可以试试:[...array()]


推荐阅读