【问题标题】:Discord bot send messages specific channel errorDiscord bot 发送消息特定通道错误
【发布时间】:2020-08-25 11:40:39
【问题描述】:

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

    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

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    由于discord.js v12需要使用cache属性访问channels集合,所以需要替换

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

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

    【讨论】: