2022-07-23 08:04:10 -04:00
|
|
|
const { EmbedBuilder } = require('discord.js');
|
2023-08-20 19:57:09 -04:00
|
|
|
const fetch = require('node-fetch'); // Adding the fetch library for HTTP requests
|
2022-07-22 18:09:13 -04:00
|
|
|
|
|
|
|
module.exports = {
|
2023-08-20 19:40:54 -04:00
|
|
|
name: "weather",
|
|
|
|
description: "Get the weather for a location",
|
|
|
|
private: false,
|
|
|
|
options: [{
|
|
|
|
name: "location",
|
2023-08-20 19:50:34 -04:00
|
|
|
description: "The location you would like to check",
|
2023-08-20 19:40:54 -04:00
|
|
|
required: true,
|
2023-08-20 19:57:09 -04:00
|
|
|
type: 3 // 3 is type STRING
|
2023-08-20 19:40:54 -04:00
|
|
|
}],
|
2022-07-22 18:09:13 -04:00
|
|
|
run: async (client, interaction) => {
|
2023-08-20 19:57:09 -04:00
|
|
|
const location = interaction.options.getString('location');
|
|
|
|
|
|
|
|
// Check if the image exists
|
|
|
|
const imageUrl = `https://wttr.in/${encodeURIComponent(location)}.png`;
|
|
|
|
try {
|
|
|
|
const response = await fetch(imageUrl);
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error("Image not found");
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
return interaction.editReply("Error: The weather image could not be found.");
|
|
|
|
}
|
2023-08-20 19:40:54 -04:00
|
|
|
|
2022-07-23 08:04:10 -04:00
|
|
|
const embed = new EmbedBuilder()
|
2022-07-22 18:09:13 -04:00
|
|
|
.setColor("#FF0000")
|
2023-08-20 19:40:54 -04:00
|
|
|
.setTitle(`The weather for: ${location}`)
|
2022-07-22 18:09:13 -04:00
|
|
|
.setTimestamp()
|
2023-08-20 19:57:09 -04:00
|
|
|
.setImage(imageUrl)
|
2023-08-20 19:52:55 -04:00
|
|
|
.setFooter({ text: `Provided by wttr.in`, iconURL: `${interaction.user.displayAvatarURL()}` });
|
2023-08-20 19:57:09 -04:00
|
|
|
|
2023-08-20 19:40:54 -04:00
|
|
|
await interaction.editReply({ embeds: [embed] });
|
2022-07-22 18:09:13 -04:00
|
|
|
},
|
2023-08-20 19:57:09 -04:00
|
|
|
};
|