update
This commit is contained in:
parent
2ae08f4dbd
commit
26a88f8525
@ -1,4 +1,5 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const fetch = require('node-fetch'); // Adding the fetch library for HTTP requests
|
||||
|
||||
module.exports = {
|
||||
name: "weather",
|
||||
@ -8,18 +9,29 @@ module.exports = {
|
||||
name: "location",
|
||||
description: "The location you would like to check",
|
||||
required: true,
|
||||
type: 3 // 6 is type USER
|
||||
type: 3 // 3 is type STRING
|
||||
}],
|
||||
run: async (client, interaction) => {
|
||||
let encodedLocation = encodeURIComponent(interaction.options._hoistedOptions[0].value);
|
||||
let location = interaction.options._hoistedOptions[0].value;
|
||||
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.");
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor("#FF0000")
|
||||
.setTitle(`The weather for: ${location}`)
|
||||
.setTimestamp()
|
||||
.setImage(`https://wttr.in/${encodedLocation}.png`)
|
||||
.setImage(imageUrl)
|
||||
.setFooter({ text: `Provided by wttr.in`, iconURL: `${interaction.user.displayAvatarURL()}` });
|
||||
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
},
|
||||
};
|
||||
};
|
@ -12,6 +12,7 @@
|
||||
"dependencies": {
|
||||
"discord.js": "^14.0.3",
|
||||
"dotenv": "^16.0.0",
|
||||
"glob": "^7.2.0"
|
||||
"glob": "^7.2.0",
|
||||
"node-fetch": "^2.6.13"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user