Compare commits

...

8 Commits

Author SHA1 Message Date
dadbb755c4 Change from C to F 2023-08-22 19:45:22 -04:00
9a4a561179 update 2023-08-20 20:08:13 -04:00
26a88f8525 update 2023-08-20 19:57:09 -04:00
2ae08f4dbd update 2023-08-20 19:52:55 -04:00
a24dbc0d5b update 2023-08-20 19:50:34 -04:00
3e6badaacd update 2023-08-20 19:48:30 -04:00
795c915c0e update 2023-08-20 19:45:32 -04:00
b816c0f1da update 2023-08-20 19:42:11 -04:00
7 changed files with 43 additions and 34 deletions

View File

@ -12,7 +12,7 @@ Structure:
**handler** - This folder contains files that read the commands folders contents.
**index.js** - This is the main file to run the bot.
**wttr_bot.js** - This is the main file to run the bot.
@ -25,11 +25,7 @@ Structure:
TOKEN = token
```
4) Go to Handler -- > index.js and change "GUIDIDHERE" to your Discord Server's Guild ID
5) Go into https://discord.com/developers/applications and enable Privileged Intents.
6) Run the bot ```node index.js```
4) Run the bot ```node wttr_bot.js```
Want to make this better? Issue a pull request!

View File

@ -1,25 +0,0 @@
const { EmbedBuilder } = require('discord.js');
module.exports = {
name: "weather",
description: "Get the weather for a location",
private: false,
options: [{
name: "location",
description: "The data you would like inside of the QR",
required: true,
type: 3 // 6 is type USER
}],
run: async (client, interaction) => {
let encodedLocation = encodeURIComponent(interaction.options._hoistedOptions[0].value);
let location = interaction.options._hoistedOptions[0].value;
const embed = new EmbedBuilder()
.setColor("#FF0000")
.setTitle(`The weather for: ${location}`)
.setTimestamp()
.setImage(`https://wttr.in/${encodedLocation}.png`)
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
await interaction.editReply({ embeds: [embed] });
},
};

37
commands/main/weather.js Normal file
View File

@ -0,0 +1,37 @@
const { EmbedBuilder } = require('discord.js');
const fetch = require('node-fetch'); // Adding the fetch library for HTTP requests
module.exports = {
name: "weather",
description: "Get the weather for a location",
private: false,
options: [{
name: "location",
description: "The location you would like to check",
required: true,
type: 3 // 3 is type STRING
}],
run: async (client, interaction) => {
const location = interaction.options.getString('location');
// Check if the image exists
const imageUrl = `https://wttr.in/${encodeURIComponent(location)}.png?u`;
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(imageUrl)
.setFooter({ text: `Provided by wttr.in`, iconURL: `${interaction.user.displayAvatarURL()}` });
await interaction.editReply({ embeds: [embed] });
},
};

View File

@ -1,4 +1,4 @@
const client = require("../index");
const client = require("../wttr_bot");
require("dotenv").config();
const { glob } = require("glob");
const { promisify } = require("util");

View File

@ -1,4 +1,4 @@
const client = require("../index");
const client = require("../wttr_bot");
client.on("ready", () => {
console.log(`${client.user.tag} is up and ready to go!`);

View File

@ -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"
}
}