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

113
Visualizações
TypeError: Cannot read properties of undefined (reading 'list') when trying to make "urban" slash command

My urban-dictionary command is working just fine as common text command but when I'm trying to make a slash command - my code breaks with TypeError: Cannot read properties of undefined (reading 'list') error! Here are my options for the command:

    "options": [
        {
            "name": "search",
            "description": "Term to search for",
            "type": 3,
            "required": true
        }
    ]

and my slash command code:

let query = interaction.options.getString('search')

        query = encodeURIComponent(query);
        const { data: { list }, } = axios.get(`https://api.urbandictionary.com/v0/define?term=${query}`).catch((err) => {})
        
        const [answer] = list;

        const embed = new MessageEmbed()
        .setTitle(answer.word)
        .setURL(answer.permalink)
        .setColor("#380002")
        .setDescription(trim(answer.definition))
        .addField("Example", trim(answer.example), false)
        .addField("Upvotes", `** ** ${answer.thumbs_up}`, true)
        .addField("Downvotes", `** ** ${answer.thumbs_down}`, true)
        .setFooter(`Author: ${answer.author}`);

        interaction.reply({embeds: [embed], ephemeral: false}).catch((err) => {})

So, any ideas on what's wrong? If you need more info I will answer in comments because I have no idea what is wrong

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

axios.get returns a Promise. This means that axios.get(...).data will be undefined. The simple fix is to add await:

//async function
const { data: { list }, } = await axios.get(`...`).catch((err) => {})
about 4 years ago · Juan Pablo Isaza 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