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

I want my bot (public) can sendMessage in specific channel. but I have an error.

error: cannot read property 'send' of undefined

0

1 Answer 1

2

The issue is in bot.channels.get(`'${channel_id}`).send(text) is not how template literals work.

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

should work.

Sign up to request clarification or add additional context in comments.

1 Comment

Then I would check if channel_id (or row.log_channel) is actually definited. It also does make sense to give the exact line the error gets thrown, since there are more than one positions where you try to send something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.