Automatically determine the bot's userId

This commit is contained in:
powermaker450 2024-06-26 19:37:20 +00:00
parent 539c31a412
commit 80b2bbaa46
2 changed files with 6 additions and 7 deletions

View file

@ -34,8 +34,3 @@ ALLOWED_CHAT=
SAFE_WORD= SAFE_WORD=
# When this character/string is detected anywhere in a message, the bot won't respond to it. Defaults to "\". # 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.

View file

@ -20,8 +20,7 @@ import { ImagesResponse } from "openai/resources";
const HOST = process.env.HOST; const HOST = process.env.HOST;
const APPID = process.env.ID; const APPID = process.env.ID;
const APPSECRET = process.env.SECRET; const APPSECRET = process.env.SECRET;
const SELF = process.env.SELF; const allVarsFilled = HOST && APPID && APPSECRET;
const allVarsFilled = HOST && APPID && APPSECRET && SELF;
if (!allVarsFilled) { if (!allVarsFilled) {
console.log("Not all required variables are filled in."); console.log("Not all required variables are filled in.");
@ -42,6 +41,11 @@ const client = new TailchatWsClient(HOST, APPID, APPSECRET);
client.connect().then(async () => { client.connect().then(async () => {
console.log("Logged in."); 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) => { client.onMessage(async (message) => {
const canRespondInGuild = const canRespondInGuild =