Changed template

This commit is contained in:
2023-04-28 11:48:43 +00:00
parent 37b0fc71ec
commit 0f4cecf9b0
16 changed files with 684 additions and 138 deletions

View File

@ -0,0 +1,97 @@
const client = require("../index");
require("dotenv").config();
const { glob } = require("glob");
const { promisify } = require("util");
const globPromise = promisify(glob);
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
if (interaction.isChatInputCommand()) {
// Grabbing Command Data for this interaction
let commandData = []
// 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)
}
});
// Process and Parse Data
let dataToProcess = JSON.stringify(commandData[0])
let parsedData = JSON.parse(dataToProcess)
if (interaction.commandName == "modal-example"){
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(() => {});
}
}
const cmd = client.slashCommands.get(interaction.commandName);
if (!cmd)
return interaction.followUp({
content: "An error has occurred "
});
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
if (interaction.isContextMenuCommand()) {
await interaction.deferReply({
ephemeral: false
});
const command = client.slashCommands.get(interaction.commandName);
if (command) command.run(client, interaction);
}
});

39
events/messageCreate.js Normal file
View File

@ -0,0 +1,39 @@
const client = require("../index");
const wolfcount = require('../models/wolfcount');
// When a message is sent, check if the message includes the letters of wolf
const wolfChars = ['w', 'o', 'l', 'f'];
client.on("messageCreate", async (message) => {
if (message.author.bot) return;
if (message.content.includes(">>")) return;
// convert the message to lowercase
const lowerMsg = message.content.toLowerCase();
// console.log(lowerMsg);
// check if the message has the letters
if (wolfChars.every(char=>lowerMsg.includes(char))) {
message.react("🐺").catch(err=>console.log(err));
newcount = basecount + 1;
// client.user.setPresence({
// // activities: [{ name: `${newcount} message(s) detected`, type: ActivityType.Watching }],
// activities: [{ name: `${newcount} message(s) detected` }],
// status: 'dnd',
// });
basecount = newcount;
console.log('');
console.log('Live wolf count:', newcount);
// update the wolf count
wolfcount.findByIdAndUpdate("6447da87681fd1bc486a4923", {count: newcount}).then(() => {
console.log('Count updated!');
}).catch((error) => {
console.error(error);
});
}
});

15
events/ready.js Normal file
View File

@ -0,0 +1,15 @@
const client = require("../index");
const { ActivityType } = require('discord.js');
client.on("ready", () => {
console.clear();
console.log(`${client.user.tag} is up and ready to go!`);
// set the status to do not disturb
// client.user.setStatus('dnd')
client.user.setPresence({
activities: [{ name: `over msgs for certain letters`, type: ActivityType.Watching }],
status: 'dnd',
});
});