简体   繁体   中英

Need help fixing a error with my weather command

so my i made a weather command but when a user puts to location it sends a error here is my command and my error is telling me if can't find length when a user doesn't put a location

else if (command === 'weather') {
         weather.find({search: args.join(" "), degreeType: "C"}, function(err, result) {
        if(err) message.channel.send(err)

        if(result.length === 0) {
            message.channel.send("**please enter a valid location**")
            return;
        }

        var current = result[0].current 
        var location = result[0].location 

        let embed = new Discord.MessageEmbed()
           .setDescription(`**${current.skytext}**`) 
           .setAuthor(`Weather for ${current.observationpoint}`) 
           .setThumbnail(current.imageUrl) 
           .setColor("RANDOM") 
           .addField("Timezone", `UTC${location.timezone}`, true) 
           .addField("Degree Type", location.degreetype, true) 
           .addField("Temperature", `${current.temperature}`, true)
           .addField("Feels like", `${current.feelslike} Degrees`, true)
           .addField("Winds", current.winddisplay, true)
           .addField("Humidity", ` ${current.humidity}%`, true)
           .addField("Day", `${current.day}`, true)
           .addField("Date", `${current.date}`, true)
           
           message.channel.send(embed)```

Return if there's an error

if(err) {
  message.channel.send(err)
  return
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM