Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
Cannot send an empty message error when trying to send Axios response in Discord.js

When I message my bot, it throws the following error:

(node:5852) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
    at c:\Users\Owner\Desktop\selfbot\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15
    at c:\Users\Owner\Desktop\selfbot\node_modules\snekfetch\src\index.js:215:21
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
<node_internals>/internal/process/warning.js:33
(node:5852) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
<node_internals>/internal/process/warning.js:33

This is my code:

bot.on("message", async function(message) {
    try {
        if (message.author == bot.user) return;
        if (message.channel.type == "dm" || message.channel.type == "group") {
            await new Promise(resolve => setTimeout(resolve, 3000));
            if (!message.channel.typing) {
                message.channel.startTyping();
                setTimeout(function() {
                    const URI = `http://api.brainshop.ai/get?bid=161231&key=80GaZTVrQICIxCnI&uid=[uid]&msg=${message}`;
                    const encodedURI = encodeURI(URI);
                    axios.get(encodedURI)
                        .then(async response => {
                            var data = response
                            message.reply(response)
                        });
                    message.channel.stopTyping();
                }, 5000);
            }
        }
    } catch (e) {
        console.log(e)
    }
});

I am making a discord bot that sends an AI-generated message to users. When I send the response, it says that it is an empty message. Am I not parsing something right?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem is that response is an object and you should send a string or an object with specific keys. As your response object doesn't have these keys, the content is empty.

Axios' get method returns an object that has a data property; it's the response that was provided by the server. The BrainShop API's response is a JSON object, with a cnt key. It probably stands for content.

To get the text content from the API, you will need to use response.data.cnt:

if (!message.channel.typing) {
  message.channel.startTyping();

  setTimeout(async () => {
    const URI = `http://api.brainshop.ai/get?bid=161231&key=80GaZTVrQICIxCnI&uid=[uid]&msg=${message}`;
    const encodedURI = encodeURI(URI);
    const response = await axios.get(encodedURI);

    message.reply(response.data.cnt);
    message.channel.stopTyping();
  }, 5000);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!