diff --git a/discordBot/discordBot.mjs b/discordBot/discordBot.mjs index 6de8500..31098ea 100644 --- a/discordBot/discordBot.mjs +++ b/discordBot/discordBot.mjs @@ -79,7 +79,7 @@ export function addEnabledEventListeners(serverClient, _eventsPath = "./events") } // The discord client -export const serverClient = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] }); +export const serverClient = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildPresences] }); // Run when the bot is ready serverClient.on('ready', async () => { diff --git a/discordBot/events/guildMemberAdd.mjs b/discordBot/events/guildMemberAdd.mjs new file mode 100644 index 0000000..d31d798 --- /dev/null +++ b/discordBot/events/guildMemberAdd.mjs @@ -0,0 +1,34 @@ +import { DebugBuilder } from "../../modules/debugger.mjs"; +const log = new DebugBuilder("server", "discordBot.events.guildMemberAdd"); +import dotenv from 'dotenv'; +dotenv.config(); +import { Events } from 'discord.js'; +import { gptHandler } from "../modules/gptHandler.mjs"; + +const welcomeChannel = process.env.WELCOME_CHANNEL_ID; + +export const name = Events.GuildMemberAdd; + +export async function execute(nodeIo, member) { + log.INFO("New user joined the server", member); + let conversation = []; + conversation.push({ + role: 'system', + content: `There has been a new user that joined. Their name is '${member.id}'. Please welcome them to the server and remind them about the rules.` + }) + + const response = await gptHandler(conversation); + if (response) { + const responseMessage = response.choices[0].message.content; + const chunkSize = 2500; + + for (let i = 0; i < responseMessage.length; i += chunkSize) { + const chunk = responseMessage.substring(i, i + chunkSize); + + log.DEBUG("Sending message chunk:", chunk); + + await nodeIo.serverClient.channels.cache.get(welcomeChannel).send(chunk); + } + } + +} \ No newline at end of file