From 80b2bbaa463eb51baa8d1a540d9bd9866acab400 Mon Sep 17 00:00:00 2001 From: powermaker450 Date: Wed, 26 Jun 2024 19:37:20 +0000 Subject: [PATCH] Automatically determine the bot's userId --- .env.example | 5 ----- src/bot.ts | 8 ++++++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index b327828..825067c 100644 --- a/.env.example +++ b/.env.example @@ -34,8 +34,3 @@ ALLOWED_CHAT= SAFE_WORD= # When this character/string is detected anywhere in a message, the bot won't respond to it. Defaults to "\". - - -SELF= -# The user ID of your bot which you can get from the admin panel or database. -# THIS IS NEEDED SO THAT THE BOT DOES NOT RESPOND TO IT'S OWN MESSAGES. diff --git a/src/bot.ts b/src/bot.ts index 42a55e6..823f3b2 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -20,8 +20,7 @@ import { ImagesResponse } from "openai/resources"; const HOST = process.env.HOST; const APPID = process.env.ID; const APPSECRET = process.env.SECRET; -const SELF = process.env.SELF; -const allVarsFilled = HOST && APPID && APPSECRET && SELF; +const allVarsFilled = HOST && APPID && APPSECRET; if (!allVarsFilled) { console.log("Not all required variables are filled in."); @@ -42,6 +41,11 @@ const client = new TailchatWsClient(HOST, APPID, APPSECRET); client.connect().then(async () => { console.log("Logged in."); + const SELF = await client.whoami().then((response) => { + return response.userId; + }); + console.log("Our userId is:", SELF); + console.log("Messages from this userId are automatically ignored."); client.onMessage(async (message) => { const canRespondInGuild =