NoMoreAcronyms/main.ts

94 lines
2.8 KiB
TypeScript

// Require the necessary discord.js classes
const { Client, Events, GatewayIntentBits, REST, Routes, Collection, FLAGS } = require('discord.js');
const Discord = require('discord.js');
const { clientId, guildId, token } = require('./key.json');
const fs = require('node:fs');
const path = require('node:path');
// Create a new client instance
const client = new Discord.Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
// When the client is ready, run this code (only once)
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
// Log in to Discord with your client's token
client.login(token);
// Retrieve commands
client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.ts'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
// Set a new item in the Collection with the key as the command name and the value as the exported module
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
// My code
var abbreviationKey = require("./abbreviation_key.json");
function updatePhraseList() {
abbreviationKey = require("./abbreviation_key.json");
}
client.on('messageCreate', message => {
console.log(`${message.author.tag} in #${message.channel.name} sent: ${message.content}`);
if (message.author.bot) {
return;
}
var messageArray = message.content.toLowerCase().split(/[ ,!@#$%^&*()]+/);
console.log(messageArray);
for (let i = 0; i < messageArray.length; ++i) {
if (abbreviationKey.target_phrases[messageArray[i]] != undefined) {
console.log("Found an abbreviation!");
break;
}
}
message.reply("Test");
console.log(abbreviationKey.target_phrases[messageArray[0]]);
}
);