Skip to content

Commit

Permalink
✨ Added response message
Browse files Browse the repository at this point in the history
  • Loading branch information
MotiCAT committed Jan 2, 2024
1 parent 998e722 commit 38dc214
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Events/onMessageCreate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ServerResponseData } from '../Utils/ServerData';
import { commands } from '../commands';
import { bannedUsers, bannedServers } from '../index';
import { Message, PermissionsBitField, Awaitable, GuildTextBasedChannel } from 'discord.js';
import { config } from 'dotenv';
import { readFileSync } from 'fs';

config();

Expand Down Expand Up @@ -34,7 +36,6 @@ export async function onMessageCreate(message: Message): Promise<Awaitable<void>
return;
}
if (
!message.content.startsWith(prefix) ||
message.author.bot ||
message.guild?.members.me?.communicationDisabledUntil !== null ||
!message.guild.members.me
Expand All @@ -43,6 +44,18 @@ export async function onMessageCreate(message: Message): Promise<Awaitable<void>
bannedServers.includes(message.guild.id)
)
return;
const rawData = readFileSync('./database/responses.json', 'utf-8');
const data: Record<string, ServerResponseData> = JSON.parse(rawData);
const serverData = data[message.guild.id];
if (serverData) {
for (const keyword in serverData) {
if (message.content.includes(keyword)) {
const response = serverData[keyword];
message.channel.send(response);
}
}
}
if (!message.content.startsWith(prefix)) return;
const args = message.content.slice(prefix.length).trim().split(/ +/) as string[];
const commandName = args.shift()?.toLowerCase();
switch (commandName) {
Expand Down

0 comments on commit 38dc214

Please sign in to comment.