获取公会中的每个频道

时间:2020-04-12 15:53:45

标签: discord.js

我试图将每个频道都放入不和谐的公会中,但这会给我一条错误消息。

if (message.content.startsWith('!get-channels')) {

    message.guild.channels.forEach(channel => {

        console.log(channel)

    })

}

这是错误消息:

                message.guild.channels.forEach(channel => {
                                       ^

TypeError: message.guild.channels.forEach is not a function
    at Client.<anonymous> (C:\Users\your user name\Desktop\dokumentumok\Discord Server Nuker\index.js:23:26)
    at Client.emit (events.js:311:20)
    at MessageCreateAction.handle (C:\Users\your user name\Desktop\dokumentumok\Discord Server Nuker\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\your user name\Desktop\dokumentumok\Discord Server Nuker\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\your user name\Desktop\dokumentumok\Discord Server Nuker\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
    at WebSocketShard.onPacket (C:\Users\your user name\Desktop\dokumentumok\Discord Server Nuker\node_modules\discord.js\src\client\websocket\WebSocketShard.js:435:22)
    at WebSocketShard.onMessage (C:\Users\your user name\Desktop\dokumentumok\Discord Server Nuker\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
    at WebSocket.onMessage (C:\Users\your user name\Desktop\dokumentumok\Discord Server Nuker\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:311:20)
    at Receiver.receiverOnMessage (C:\Users\your user name\Desktop\dokumentumok\Discord Server Nuker\node_modules\ws\lib\websocket.js:801:20)

1 个答案:

答案 0 :(得分:1)

您会收到此错误,因为自discord.js v12起,您现在需要使用其cache访问公会频道,因此您的解决方案是使用message.guild.channels.cache.forEach()