如何使用Weather命令修复错误

时间:2020-08-24 12:30:37

标签: javascript bots discord.js

const Discord = require('discord.js');

const weather = require('weather-js');
 
module.exports = {
    name: 'weather',
    description: 'weather',
    execute(message, args){
        const { prefix, token } = require ('../config.json');

        if(!args.length) {
            return message.channel.send("Please give the weather location")
        }
    
    weather.find({search: args.join(" "), degreeType: 'C'}, function(err, result) {
        try {
 
let embed = new discord.MessageEmbed()
.setTitle(`weather - ${result[0].location.name}`)
.setColor("#fffff1")
.setDescription("Temperature units can may be differ some time")
.addField("Temperature", `${result[0].current.temperature} Celcius`, true)
.addField("Sky Text", result[0].current.skytext, true)
.addField("Humidity", result[0].current.humidity, true)
.addField("Wind Speed", result[0].current.windspeed, true)//What about image
.addField("Observation Time", result[0].current.observationtime, true)
.addField("Wind Display", result[0].current.winddisplay, true)
.setThumbnail(result[0].current.imageUrl);
   message.channel.send(embed)
} catch(err) {
  return message.channel.send("Unable To Get the data of Given location")
}
});   
}
}

当我使用命令!weather 时,正常显示Provides the location of the climate

但是,如果我放置城市,例如!天气洛杉矶,它总是会给我错误Unable To Get the data of Given location,我放置的任何城市都总是这样。

1 个答案:

答案 0 :(得分:0)

说...您是否意识到不和谐标识符是错误的?

const Discord = require('discord.js')

然后

...
let embed = new discord.MessageEmbed()
...

尝试将其更改为:

...
let embed = new Discord.MessageEmbed()
...