Update Discord.ts

This commit is contained in:
2021-09-15 04:10:50 -07:00
parent a50b9abb00
commit 736863922e
+35 -7
View File
@@ -1,10 +1,14 @@
import {Client, Intents, TextChannel} from "discord.js";
import {Client, GuildMember, Intents, Interaction, Message, TextChannel} from "discord.js";
import Logger from "../libs/Logger";
import Environment from "./Environment";
import Discord_Core from "../discord/core";
import Discord_Ping from "../discord/ping";
import Discord_Core from "../discord/Core";
import Discord_Ping from "../discord/Ping";
import Discord_Help from "../discord/Help";
import Discord_Invite from "../discord/Invite";
import Discord_Say from "../discord/Say";
import Discord_MembershipScreening from "../discord/MembershipScreening";
import Cache from "./Cache";
class Discord {
@@ -15,7 +19,7 @@ class Discord {
constructor () {
this.client = new Client({
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS]
});
this.loaded_module = {};
}
@@ -24,8 +28,14 @@ class Discord {
Logger.info('Logging in to discord');
this.client.login(Environment.get().DISCORD_TOKEN);
// TODO: Improve this
this.loaded_module["Core"] = new Discord_Core();
this.loaded_module["Ping"] = new Discord_Ping();
this.loaded_module["Discord_Help"] = new Discord_Help();
this.loaded_module["Discord_Invite"] = new Discord_Invite();
this.loaded_module["Discord_Say"] = new Discord_Say();
this.loaded_module["MembershipScreening"] = new Discord_MembershipScreening();
for(const module in this.loaded_module) {
let thisModule = this.loaded_module[module];
@@ -43,7 +53,25 @@ class Discord {
}
});
this.client.on("messageCreate", message => {
this.client.on("guildMemberAdd", (member: GuildMember) => {
for(const module in this.loaded_module) {
let thisModule = this.loaded_module[module];
if (typeof thisModule.guildMemberAdd === "function")
thisModule.guildMemberAdd(member);
}
});
this.client.on("interactionCreate", (interaction: Interaction) => {
for(const module in this.loaded_module) {
let thisModule = this.loaded_module[module];
if (typeof thisModule.interactionCreate === "function")
thisModule.interactionCreate(interaction);
}
});
this.client.on("messageCreate", (message: Message) => {
for(const module in this.loaded_module) {
let thisModule = this.loaded_module[module];
@@ -53,11 +81,11 @@ class Discord {
});
// Handling commands
this.client.on("messageCreate", async (message) => {
this.client.on("messageCreate", async (message: Message) => {
// TODO: Handle DMs commands soon
if(!(message.channel instanceof TextChannel)) return;
if(message.author.bot) return;
//if(message.author.bot) return;
if(typeof message.guild?.id === 'undefined') return;