mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-03 23:36:35 +02:00
47 lines
2.3 KiB
JavaScript
47 lines
2.3 KiB
JavaScript
const Discord = require('discord.js');
|
|
const axios = require('axios');
|
|
|
|
module.exports = {
|
|
name: 'weather',
|
|
description: 'Affiche les informations météorologiques d\'une ville',
|
|
category: 'utils',
|
|
emote: '☀️',
|
|
utilisation: 'weather [ville]',
|
|
async execute(message, args) {
|
|
try {
|
|
const APIKEY = '1e59407044fd6d842180610a8c423aa4';
|
|
const city = args[0];
|
|
const randomColor = Math.floor(Math.random() * 16777215).toString(16);
|
|
if (!city) {
|
|
return message.channel.send('Veuillez fournir une ville.');
|
|
}
|
|
|
|
const response = await axios.get(`https://api.openweathermap.org/data/2.5/weather?q=${encodeURIComponent(city)}&appid=${APIKEY}&units=metric`);
|
|
const weatherData = response.data;
|
|
|
|
const cityName = weatherData.name;
|
|
const temperature = weatherData.main.temp;
|
|
const weatherDescription = weatherData.weather[0].description;
|
|
const humidity = weatherData.main.humidity;
|
|
const pressure = weatherData.main.pressure;
|
|
const windSpeed = weatherData.wind.speed;
|
|
const windDirection = weatherData.wind.deg;
|
|
const visibility = weatherData.visibility;
|
|
const feelsLike = weatherData.main.feels_like;
|
|
const weatherIcon = weatherData.weather[0].icon;
|
|
|
|
const Embed = new Discord.EmbedBuilder()
|
|
.setTitle(`Meteo à ${cityName}`)
|
|
.setDescription(`🌡・Temperature: ${temperature}°C\n⛅・Temps: ${weatherDescription}\n💧・Humidité: ${humidity}%\n📊・Pression: ${pressure} hPa\n💨・Vitesse du vent: ${windSpeed} m/s\n🧭・Direction du vent: ${windDirection}°\n👁️🗨️・Visibilité: ${visibility} m\n🌡️・Sensation de température: ${feelsLike}°C`)
|
|
.setTimestamp()
|
|
.setColor(`#${randomColor}`)
|
|
.setFooter({text: message.client.user.username, iconURL: message.client.user.displayAvatarURL({dynamic: true})})
|
|
.setThumbnail(`http://openweathermap.org/img/wn/${weatherIcon}.png`);
|
|
|
|
await message.channel.send({ embeds: [Embed] });
|
|
} catch(e) {
|
|
console.error(e);
|
|
await message.channel.send(`Je n'ai pas trouvé la ville ${city}!`);
|
|
}
|
|
},
|
|
}; |