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