#when using undici follow the guide in discordjs guide it shows me cannot read properties of undefin

8 messages · Page 1 of 1 (latest)

vital stratus
frigid inletBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
vital stratus
const { request } = require('undici');
module.exports = {
    data: new SlashCommandBuilder()
        .setName('test')
        .setDescription('test')
    .addStringOption(option =>
            option
                .setName('term') 
              .setDescription('The VTC ID which invite us to partcipate')
        .setRequired(true)
    ),
    async execute(interaction) {
    await interaction.deferReply();
    const term = interaction.options.getString('term');
        const query = new URLSearchParams({ term });

        const dictResult = await request(`https://api.truckersmp.com/v2/vtc/${query}`);
        const { list } = await dictResult.body.json();
    if (!list.length) {
      return interaction.editReply(`No results found for **${term}**.`);
    }
    interaction.editReply(`**${term}**: ${list[0].definition}`);
  }
};```
digital void

Log list

tawny hill

It's undefined. It's better to log the parsed json body

marble niche

the api endpoint doesn't return a list property

vital stratus

if i just want the url followed number such as 10056 how can i code the urlsearch params