Compare commits
8 Commits
e895ff8fbd
...
master
Author | SHA1 | Date | |
---|---|---|---|
dadbb755c4 | |||
9a4a561179 | |||
26a88f8525 | |||
2ae08f4dbd | |||
a24dbc0d5b | |||
3e6badaacd | |||
795c915c0e | |||
b816c0f1da |
@ -12,7 +12,7 @@ Structure:
|
|||||||
|
|
||||||
**handler** - This folder contains files that read the commands folders contents.
|
**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
|
TOKEN = token
|
||||||
```
|
```
|
||||||
|
|
||||||
4) Go to Handler -- > index.js and change "GUIDIDHERE" to your Discord Server's Guild ID
|
4) Run the bot ```node wttr_bot.js```
|
||||||
|
|
||||||
5) Go into https://discord.com/developers/applications and enable Privileged Intents.
|
|
||||||
|
|
||||||
6) Run the bot ```node index.js```
|
|
||||||
|
|
||||||
|
|
||||||
Want to make this better? Issue a pull request!
|
Want to make this better? Issue a pull request!
|
||||||
|
@ -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
37
commands/main/weather.js
Normal 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] });
|
||||||
|
},
|
||||||
|
};
|
@ -1,4 +1,4 @@
|
|||||||
const client = require("../index");
|
const client = require("../wttr_bot");
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
const { glob } = require("glob");
|
const { glob } = require("glob");
|
||||||
const { promisify } = require("util");
|
const { promisify } = require("util");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const client = require("../index");
|
const client = require("../wttr_bot");
|
||||||
|
|
||||||
client.on("ready", () => {
|
client.on("ready", () => {
|
||||||
console.log(`${client.user.tag} is up and ready to go!`);
|
console.log(`${client.user.tag} is up and ready to go!`);
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user