簡體   English   中英

node.js discord.js 無法讀取未定義的屬性“發送”

[英]node.js discord.js cannot read property 'send' of undefined

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)
    }
}

我希望我的機器人(公共)可以在特定頻道中發送消息。 但我有一個錯誤。

錯誤:無法讀取未定義的屬性“發送”

問題出在bot.channels.get( '${channel_id} ).send(text)這不是模板文字的工作方式。

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

應該管用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM