node.js discord.js无法读取未定义的属性“发送”

时间:2020-02-23 03:27:23

标签: javascript discord.js

if (message.content.startsWith("-send")) {
    if (message.author.id === '405714654065721344') {
        var text = message.content.substring(6)
        db.serialize();
        db.all(`SELECT log_channel FROM log_value`, function (err, rows) {
            if (!err) {
                rows.forEach(function (row) {
                    message.channel.send(row.log_channel)
                    let channel_id = row.log_channel;
                    console.log(channel_id)
                    parseInt(channel_id)
                    try {
                        bot.channels.get(`'${channel_id}`).send(text)
                    } catch (err) {
                        console.log(err)
                    }
                });
            } else {
                console.log(err)
            }
        })
    } else {
        return error.noPerms(message, "BOT DEVELOPS", message.author.username)
    }
}

我希望我的机器人(公共)可以在特定频道中发送sendMessage。 但我有一个错误。

错误:无法读取未定义的属性“发送”

1 个答案:

答案 0 :(得分:0)

问题出在bot.channels.get('$ {channel_id} ).send(text)中,而不是template literals的工作原理。

bot.channels.get(channel_id).send(text)

应该工作。