简体   繁体   English

如何修复天气命令的错误

[英]How to fix an error with the weather command

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")
}
});   
}
}

When I use the command !weather , works normally showing Provides the location of the climate当我使用命令!weather 时,正常工作显示Provides the location of the climate

But if I place the city, for example !weather Los Angeles , it always gives me the error Unable To Get the data of Given location , any city I place always appears like this.但是如果我放置城市,例如!weather Los Angeles ,它总是给我错误Unable To Get the data of Given location ,我放置的任何城市总是这样出现。

Say... did you realize your discord identifier is wrong?说...你有没有意识到你的不和谐标识符是错误的?

const Discord = require('discord.js')

then然后

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

Try Changing it to:尝试将其更改为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与天气命令混淆,我该如何解决? - confusion with weather command, how do i fix it? 如何以角度修复循环预测天气 - How to fix the looping forecast weather in angular 如何修复类型错误无法读取天气预报项目中未定义的属性“cityName”? - How to fix Type Error cannot read property 'cityName' of undefined in the weather forecast project? 如何在运行 CLI 命令时修复此错误“语法错误” - How to fix this error "Syntax Error" while running CLI command 如何修复错误“TypeError: cy.[custom command] is not a function”? - How to fix the Error "TypeError: cy.[custom command] is not a function"? 如何使用weather api删除天气预报中的第一个天气 - How to remove the first weather in weather forecast using weather api 如何刷新天气层? - How to refresh the weather layer? 如何解决“第72行错误:错误:sh:img2pdf:找不到命令” - How to fix “Error on line 72: Error: sh: img2pdf: command not found” 天气 API 请求 cors 错误 - Weather API request cors error 在 Mac 上使用命令 'sudo npm install electron -g' 在 Mac 上安装 Electron 后如何修复此错误 - How can I fix this error after installing Electron on Mac with command 'sudo npm install electron -g'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM