Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
undefined (reading 'videos')

Trying to get a discord bot to join a channel and play a link but I get this error

TypeError: Cannot read properties of undefined (reading 'videos')

my command handler is fine with other simpler commands

    const videoFinder = async (query) => {
        const videoResult = await ytSearch(query);

        return (videoResult.videos.length > 1) ? videoResult.videos[0] : null;
    }

This is the line that gets me the error

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You may try something like this :

const videoFinder = async (query) => {
        const videoResult = await ytSearch(query);

        return (videoResult?.videos?.length > 1) ? videoResult?.videos[0] : null;
    }

The ? will check the object before exists. If not, it returns undefined and in your case, null, because undefined.videos doesn't exist.

Alternatively :

const videoFinder = async (query) => {
        const videoResult = await ytSearch(query);
        if (!videoResult || !videoResult.videos) return null
        return videoResult.videos[0]
    }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!