Discord bot发送消息特定的通道错误

时间:2020-05-09 21:45:14

标签: javascript node.js discord discord.js

我希望在发出命令时将消息发送到特定的频道。如果命令未在特定通道上运行,我希望用户遇到错误。我需要你的帮助。

    if (msg.author.bot) return;
    if (msg.content.toLowerCase() === prefix + 'xgif' ) {
        number = 100;
        imageNumber = Math.floor (Math.random() * (number -1 + 1)) + 1;
        client.channels.get(`channelID`).send( {files: ["./images/" + imageNumber + ".gif"]})
    }

错误:TypeError: client.channels.get is not a function

1 个答案:

答案 0 :(得分:2)

从discord.js v12开始,您需要使用cache属性来访问channels集合,因此需要替换

client.channels.get(`channelID`).send( {files: ["./images/" + imageNumber + ".gif"]})

使用

client.channels.cache.get(`channelID`).send( {files: ["./images/" + imageNumber + ".gif"]})