0
votes

I've been working on a Guilded Bot that automatically runs a function after x amount of MS. My goal is to automate this function to check a website for new posts. The issue I'm encountering is when trying to import the function and call on it within another file. None of the recommended methods I've found seem to work. Below is my code.

//relay.ts under ./automations/
async function patchNotes(message:Message) {
}
export { patchNotes }
//The main file in src its called index.ts

import path from "path";
import { BotClient, Client, Message } from "@guildedjs/gil";
const { token, token2 } = require('./config.json');

import { patchNotes } from './automations/relay';

const client = new BotClient({
  token: token,
  prefix: "/",
});

client.once('ready', () => console.log('Ready! Shut down using "ctrl+c"'));

client.login();

process.on("unhandledRejection", console.log)
//setTimeout(() => console.log(client.commands), 600);

// Automations

patchNotes
setInterval(() => patchNotes, 6000);

Currently, this method doesn't return console errors for both Types and other stuff. But it also doesn't run the code at all? I've tried other methods too but none have worked so far. Below are what packages I'm using.

  • ts-node "10.8.1"
  • typescript "4.7.4" It's running Node.js and all files are written in TS. If you need any more details, I'd be happy to give them. Really hoping to get past this issue instead of just putting the function in my main file.
the first patchNotes is a method invocation, so you need brackets, i.e patchNotes('message to show'). The second patchNotes in interval won't work in general because setInterval does not wait async task to complete. If you looking for repeated task scheduler, I recommend have a look on bulljs - webdev_jj