#when using undici follow the guide in discordjs guide it shows me cannot read properties of undefin
8 messages · Page 1 of 1 (latest)
- 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!
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}`);
}
};```
Log list
It's undefined. It's better to log the parsed json body
the api endpoint doesn't return a list property
I suggest you look at the returned json in a browser, for example https://api.truckersmp.com/v2/vtc/foxlog-group and then go from there
if i just want the url followed number such as 10056 how can i code the urlsearch params