Compare commits
No commits in common. "e895ff8fbd3f36d5dc6bb4ae832d0db2abb9bb4a" and "215ac4cd6f84a5d82068d7e64f267df3210d340f" have entirely different histories.
e895ff8fbd
...
215ac4cd6f
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
node_modules
|
|
||||||
.env
|
|
||||||
package-lock.json
|
|
@ -1,4 +1,4 @@
|
|||||||
# WTTR BOT
|
# Discord-Linx Discord.JS v14 Base Template
|
||||||
|
|
||||||
Only 3 dependencies required to run this bot!
|
Only 3 dependencies required to run this bot!
|
||||||
|
|
||||||
@ -25,9 +25,9 @@ Structure:
|
|||||||
TOKEN = token
|
TOKEN = token
|
||||||
```
|
```
|
||||||
|
|
||||||
4) Go to Handler -- > index.js and change "GUIDIDHERE" to your Discord Server's Guild ID
|
4) Go to Handler -- > index.js and change "GUIDIDHERE" to your Discord Servers Guild ID
|
||||||
|
|
||||||
5) Go into https://discord.com/developers/applications and enable Privileged Intents.
|
5) Go into https://discord.com/developers/applications and enable Privlaged Intents.
|
||||||
|
|
||||||
6) Run the bot ```node index.js```
|
6) Run the bot ```node index.js```
|
||||||
|
|
||||||
|
@ -1,25 +1,16 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "weather",
|
name: "ping",
|
||||||
description: "Get the weather for a location",
|
description: "Returns websocket latency",
|
||||||
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;
|
|
||||||
|
|
||||||
|
run: async (client, interaction) => {
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setColor("#FF0000")
|
.setColor("#FF0000")
|
||||||
.setTitle(`The weather for: ${location}`)
|
.setTitle("🏓 Pong!")
|
||||||
|
.setDescription(`Latency : ${client.ws.ping}ms`)
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setImage(`https://wttr.in/${encodedLocation}.png`)
|
|
||||||
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
|
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
|
||||||
await interaction.editReply({ embeds: [embed] });
|
interaction.followUp({ embeds: [embed] });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,97 +1,33 @@
|
|||||||
const client = require("../index");
|
const client = require("../index");
|
||||||
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(() => { });
|
||||||
|
|
||||||
// Grabbing Command Data for this interaction
|
const cmd = client.slashCommands.get(interaction.commandName);
|
||||||
let commandData = []
|
if (!cmd)
|
||||||
|
return interaction.followUp({ content: "An error has occurred " });
|
||||||
|
|
||||||
// We use ForEach here to filter our array into the single commands info.
|
const args = [];
|
||||||
await arrayOfSlashCommands.forEach(command => {
|
|
||||||
if (command.name == interaction.commandName) {
|
|
||||||
commandData.push(command)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Process and Parse Data
|
for (let option of interaction.options.data) {
|
||||||
let dataToProcess = JSON.stringify(commandData[0])
|
if (option.type === "SUB_COMMAND") {
|
||||||
let parsedData = JSON.parse(dataToProcess)
|
if (option.name) args.push(option.name);
|
||||||
|
option.options?.forEach((x) => {
|
||||||
|
if (x.value) args.push(x.value);
|
||||||
if (interaction.commandName == "modal-example"){
|
});
|
||||||
console.log("Modal - Skipping defer")
|
} else if (option.value) args.push(option.value);
|
||||||
} 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(() => {});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const cmd = client.slashCommands.get(interaction.commandName);
|
interaction.member = interaction.guild.members.cache.get(interaction.user.id);
|
||||||
if (!cmd)
|
|
||||||
return interaction.followUp({
|
|
||||||
content: "An error has occurred "
|
|
||||||
});
|
|
||||||
|
|
||||||
const args = [];
|
cmd.run(client, interaction, 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({
|
await interaction.deferReply({ ephemeral: false });
|
||||||
ephemeral: false
|
const command = client.slashCommands.get(interaction.commandName);
|
||||||
});
|
if (command) command.run(client, interaction);
|
||||||
const command = client.slashCommands.get(interaction.commandName);
|
|
||||||
if (command) command.run(client, interaction);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
2
index.js
2
index.js
@ -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: 4097 });
|
const client = new Client({ intents: 32767 });
|
||||||
module.exports = client;
|
module.exports = client;
|
||||||
|
|
||||||
// Global Variables
|
// Global Variables
|
||||||
|
Loading…
x
Reference in New Issue
Block a user