xyter/src/events/messageUpdate/modules/counter.ts
2022-04-14 04:00:34 +02:00

35 lines
939 B
TypeScript

// Dependencies
import { Message } from "discord.js";
// Models
import counterSchema from "@schemas/counter";
import logger from "@logger";
export default async (message: Message) => {
const { guild, channel, author, content } = message;
const counter = await counterSchema?.findOne({
guildId: guild?.id,
channelId: channel?.id,
});
if (counter === null)
return logger?.verbose(
`No counter found for guild: ${guild?.name} (${guild?.id})`
);
const { word } = counter;
if (content === word)
return logger?.verbose(
`User: ${author?.tag} (${author?.id}) in guild: ${guild?.name} (${guild?.id}) said the counter word: ${word}`
);
await message
?.delete()
?.then(async () => {
await channel?.send(`${author} said **${word}**.`);
logger?.verbose(`${author} said ${word} in ${channel}`);
})
?.catch(async (error: any) => {
logger?.error(error);
});
};