#Automatically create thread

1 messages · Page 1 of 1 (latest)

empty nexus
#

I wonder if possible to automatically create thread at every midnight in my own server.

left compassBOT
pure folio
#

sure, you can use a library to make cron schedules where a function gets called at the time you want, just make that function create the thread

empty nexus
#

I'm sorry but I'm new here, can you provide some visuals

zealous rampart
#

as an example, like Amgelo said, you could use the package node-cron (linked in #resources) that can schedule a function to be run with the provided cron expression

since you did specify for it to be created each day at midnight, the expression 0 0 * * * can be used

small example of how it can be set up:

import { schedule } from "node-cron";

schedule("0 0 * * *", () => {
    // Create a thread on a channel using channel.threads.create({ ... })
});
subtle rampartBOT
#

method GuildTextThreadManager#create() discord.js@14.26.4
Creates a new thread in the channel.


// Create a new public thread
channel.threads
  .create({
    name: 'food-talk',
    autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
    reason: 'Needed a separate thread for food',
  })
  .then(threadChannel => console.log(threadChannel))
  .catch(console.error);