const { SlashCommandBuilder } = require('discord.js'); const axios = require('axios'); const { EmbedBuilder } = require('discord.js'); module.exports = { data: new SlashCommandBuilder() .setName('időjárás') .setDescription('Megmutatja az aktuális időjárást a legnagyobb magyar városokban.'), async execute(interaction) { const apiKey = '3935757f8a8329766edb2ed5219a2e11'; const cities = ['Budapest', 'Debrecen', 'Szeged', 'Miskolc', 'Pécs', 'Győr']; const weatherData = []; for (const city of cities) { const url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric&lang=hu`; const response = await axios.get(url); const data = response.data; const sunriseTime = new Date(data.sys.sunrise * 1000).toLocaleTimeString('hu-HU', { hour: '2-digit', minute: '2-digit' }); const sunsetTime = new Date(data.sys.sunset * 1000).toLocaleTimeString('hu-HU', { hour: '2-digit', minute: '2-digit' }); weatherData.push({ name: city, temperature: data.main.temp, minTemp: data.main.temp_min, maxTemp: data.main.temp_max, description: data.weather[0].description, icon: `http://openweathermap.org/img/w/${data.weather[0].icon}.png`, sunrise: sunriseTime, sunset: sunsetTime, moonrise: 'N/A', // Placeholder érték, mivel OpenWeather API nem támogatja a holdkelte/holdnyugta adatokat. moonset: 'N/A' // Placeholder érték. }); } const weatherEmbed = new EmbedBuilder() .setTitle('🌦 Időjárásjelentés') .setDescription('A mai napra vonatkozó időjárásjelentés Magyarország legnagyobb városaiban.') .setColor(0x00AE86) .setTimestamp(); weatherData.forEach(cityWeather => { weatherEmbed.addFields( { name: cityWeather.name, value: `**${cityWeather.description.charAt(0).toUpperCase() + cityWeather.description.slice(1)}**\n` + `🌡 **Max:** ${cityWeather.maxTemp}°C | **Min:** ${cityWeather.minTemp}°C\n` + `🌅 **Napkelté:** ${cityWeather.sunrise}\n` + `🌇 **Napnyugta:** ${cityWeather.sunset}\n` + `🌕 **Holdkelte:** ${cityWeather.moonrise}\n` + `🌑 **Holdnyugta:** ${cityWeather.moonset}\n` + `![Icon](${cityWeather.icon})` , inline: true } ); }); await interaction.reply({ embeds: [weatherEmbed] }); }, };