Compare commits

..

19 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
e895ff8fbd first commit 2023-08-20 19:40:54 -04:00
26621c9866 modal patch to interactionCreate 2023-04-22 23:11:37 +02:00
a31234b717 adding discord modal example 2023-04-22 23:08:04 +02:00
1af66c7c00 Merge branch 'master' of git.codingvm.codes:snxraven/DiscordJS-v13-Template 2022-10-12 00:56:58 -04:00
9420839679 Changing bitfield to no longer need privileged intents 2022-10-12 00:56:45 -04:00
93c3dfa65e Adding an Example ContentMenu Command 2022-09-28 19:05:07 -04:00
cbc6740e46 Removing files 2022-09-28 18:02:34 -04:00
d88e07a7ed adding a private option within the command config and adding ephemeral support by default 2022-09-28 18:00:36 -04:00
5d5c9e9a48 update 2022-09-22 12:01:36 -04:00
0910992bdf Merge pull request 'Update 'README.md'' (#2) from LauraOrchid/DiscordJS-v14-Template:lauraorchid-patch-1 into master
Reviewed-on: https://git.codingvm.codes/snxraven/DiscordJS-v14-Template/pulls/2
2022-07-23 12:46:04 +00:00
560e62fa53 Update 'README.md'
Fixed few "obvious" typos.
2022-07-23 12:27:51 +00:00
9 changed files with 133 additions and 48 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
node_modules
.env
package-lock.json

View File

@ -1,4 +1,4 @@
# Discord-Linx Discord.JS v14 Base Template # WTTR BOT
Only 3 dependencies required to run this bot! Only 3 dependencies required to run this bot!
@ -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 Servers Guild ID 4) Run the bot ```node wttr_bot.js```
5) Go into https://discord.com/developers/applications and enable Privlaged 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!

View File

@ -1,16 +0,0 @@
const { EmbedBuilder } = require('discord.js');
module.exports = {
name: "ping",
description: "Returns websocket latency",
run: async (client, interaction) => {
const embed = new EmbedBuilder()
.setColor("#FF0000")
.setTitle("🏓 Pong!")
.setDescription(`Latency : ${client.ws.ping}ms`)
.setTimestamp()
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
interaction.followUp({ 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,33 +1,97 @@
const client = require("../index"); const client = require("../wttr_bot");
require("dotenv").config();
const { glob } = require("glob");
const { promisify } = require("util");
const globPromise = promisify(glob);
client.on("interactionCreate", async (interaction) => { client.on("interactionCreate", async (interaction) => {
// Slash Commands
const slashCommands = await globPromise(`${process.cwd()}/commands/*/*.js`);
const arrayOfSlashCommands = [];
// Map the slash commands into data to be processed
slashCommands.map((value) => {
const file = require(value);
const splitted = value.split("/");
const directory = splitted[splitted.length - 2];
if (!file?.name) return;
const properties = {
directory,
...file
};
client.slashCommands.set(file.name, properties);
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
// Push the data
arrayOfSlashCommands.push(file);
});
// Slash Command Handling // Slash Command Handling
if (interaction.isChatInputCommand()) { if (interaction.isChatInputCommand()) {
await interaction.deferReply({ ephemeral: false }).catch(() => { });
const cmd = client.slashCommands.get(interaction.commandName); // Grabbing Command Data for this interaction
if (!cmd) let commandData = []
return interaction.followUp({ content: "An error has occurred " });
const args = []; // We use ForEach here to filter our array into the single commands info.
await arrayOfSlashCommands.forEach(command => {
if (command.name == interaction.commandName) {
commandData.push(command)
}
});
for (let option of interaction.options.data) { // Process and Parse Data
if (option.type === "SUB_COMMAND") { let dataToProcess = JSON.stringify(commandData[0])
if (option.name) args.push(option.name); let parsedData = JSON.parse(dataToProcess)
option.options?.forEach((x) => {
if (x.value) args.push(x.value);
}); if (interaction.commandName == "modal-example"){
} else if (option.value) args.push(option.value); console.log("Modal - Skipping defer")
} else {
// If the command is private, set ephemeral true else, set false
console.log(parsedData)
if (parsedData.private == true) {
await interaction.deferReply({
ephemeral: true
}).catch(() => {});
} else {
await interaction.deferReply({
ephemeral: false
}).catch(() => {});
}
} }
interaction.member = interaction.guild.members.cache.get(interaction.user.id); const cmd = client.slashCommands.get(interaction.commandName);
if (!cmd)
return interaction.followUp({
content: "An error has occurred "
});
cmd.run(client, interaction, args); const args = [];
for (let option of interaction.options.data) {
if (option.type === "SUB_COMMAND") {
if (option.name) args.push(option.name);
option.options?.forEach((x) => {
if (x.value) args.push(x.value);
});
} else if (option.value) args.push(option.value);
}
interaction.member = interaction.guild.members.cache.get(interaction.user.id);
cmd.run(client, interaction, args);
} }
// Context Menu Handling // Context Menu Handling
if (interaction.isContextMenuCommand()) { if (interaction.isContextMenuCommand()) {
await interaction.deferReply({ ephemeral: false }); await interaction.deferReply({
const command = client.slashCommands.get(interaction.commandName); ephemeral: false
if (command) command.run(client, interaction); });
const command = client.slashCommands.get(interaction.commandName);
if (command) command.run(client, interaction);
} }
}); });

View File

@ -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!`);

View File

@ -27,11 +27,11 @@ module.exports = async (client) => {
// Slash Commands Register // Slash Commands Register
client.on("ready", async () => { client.on("ready", async () => {
// Register for a single guild // // Register for a single guild
await client.guilds.cache.get("GUIDIDHERE").commands.set(arrayOfSlashCommands); // await client.guilds.cache.get("GUIDIDHERE").commands.set(arrayOfSlashCommands);
// Register for all the guilds the bot is in // Register for all the guilds the bot is in
// await client.application.commands.set(arrayOfSlashCommands); await client.application.commands.set(arrayOfSlashCommands);
}); });
}; };

View File

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

View File

@ -1,7 +1,7 @@
require("dotenv").config(); require("dotenv").config();
const { Client, Collection } = require("discord.js"); const { Client, Collection } = require("discord.js");
const client = new Client({ intents: 32767 }); const client = new Client({ intents: 4097 });
module.exports = client; module.exports = client;
// Global Variables // Global Variables