Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

112
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda