Haha-Yes/commands/fun/weather.js

37 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-09-26 13:23:45 +02:00
const { Command } = require('discord.js-commando');
const Discord = require('discord.js');
const snekfetch = require('snekfetch');
2018-09-26 13:35:54 +02:00
const { openweatherAPI } = require('../../config.json');
2018-09-26 13:23:45 +02:00
module.exports = class WeatherCommand extends Command {
constructor(client) {
super(client, {
name: 'weather',
group: 'fun',
memberName: 'weather',
description: `Choose the city you want to know the weather`,
args: [
{
key: 'city',
prompt: 'city',
type: 'string',
}
]
});
}
async run(message, { city }) {
const { body } = await snekfetch.get(`https://api.openweathermap.org/data/2.5/weather?q=${city}&units=metric&APPID=${openweatherAPI}`);
2018-09-26 13:23:45 +02:00
if (!body.main.temp) {
return message.say(`No results found for **${city}**`);
}
2018-09-26 13:35:54 +02:00
const weatherEmbed = new Discord.RichEmbed()
2018-09-26 13:23:45 +02:00
.setColor("#ff9900")
.setTitle(body.name + ' current weather')
.setDescription(body.main.temp + '°c')
.addField('Temp min', body.main.temp_min + '°c')
.addField('Temp max', body.main.temp_max + '°c')
2018-09-26 13:35:54 +02:00
message.say(weatherEmbed);
2018-09-26 13:23:45 +02:00
}
};