Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

199
Visualizações
I'm getting [object Object] instead of output

So, I have a command that should send random fact and translate it from English to Ukrainian, but instead of getting a random fact, it's just showing [object Object]. Here is my code, I'm on discord.js v13.

const { MessageEmbed } = require('discord.js');
const fetch = require('node-fetch');
const translate = require('@iamtraction/google-translate');
module.exports = {
  name: 'fact',
  description: 'Випадковий факт',
  category: 'Fun',
  async run({ interaction, bot }) {
    const response = await fetch('https://uselessfacts.jsph.pl/random.json?language=en');
await response.json().then(async res => {
const translated = await translate(res, { to: 'uk' });
      interaction.reply({
        embeds: [new MessageEmbed().setTitle('Факт').setDescription(translated.text).setColor('RANDOM')]
      });
    });
  }
};
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It's because the API returns an object and you implicitly convert it to a string. This object has a text property, so you should use await translate(res.text, { to: 'uk' }).

Also, you should not mix thens with async/await. Just pick one:

const { MessageEmbed } = require('discord.js');
const fetch = require('node-fetch');
const translate = require('@iamtraction/google-translate');
module.exports = {
  name: 'fact',
  description: 'Випадковий факт',
  category: 'Fun',
  async run({ interaction, bot }) {
    const response = await fetch(
      'https://uselessfacts.jsph.pl/random.json?language=en',
    );
    const { text } = await response.json();
    const translated = await translate(text, { to: 'uk' });
    interaction.reply({
      embeds: [
        new MessageEmbed()
          .setTitle('Факт')
          .setDescription(translated.text)
          .setColor('RANDOM'),
      ],
    });
  },
};
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda