Exit the Client Ready event

Good evening, I have a js script which is used for a cron task, so I would like it to stop by itself after execution, but I use the ready event, and the script continues to run even after the commands have finished. Is it possible to stop the script after the end of the code in the event ready? Thank you in avance !
6 Replies
d.js toolkit
d.js toolkitβ€’12mo ago
β€’ What's your exact discord.js npm list discord.js and node node -v version? β€’ Post the full error stack trace, not just the top part! β€’ Show your code! β€’ Explain what exactly your issue is. β€’ Not a discord.js issue? Check out #useful-servers.
Darth Vader
Darth Vaderβ€’12mo ago
Are you trying to stop execution of the complete program right after starting your bot and executing a few commands? If so you can use process.exit()
Syjalo
Syjaloβ€’12mo ago
What are you doing in your task? Probably you don't need the Gateway and you should use @discordjs/rest or @discordjs/core
Loris 🐐
Loris πŸβ€’12mo ago
Hmm, using process.exit() cancels the actions in my case Several tasks to get content from sqlite and a message sent with client.channels.cache.get(<id>).send("test")
Syjalo
Syjaloβ€’12mo ago
Yeah, you don't need the gateway, caching and other stuff discord.js provides.
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v10';

const rest = new REST({ version: '10' }).setToken('token');

await rest.post(Routes.channelMessages('channelId'), { body: { content: 'text' } });
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v10';

const rest = new REST({ version: '10' }).setToken('token');

await rest.post(Routes.channelMessages('channelId'), { body: { content: 'text' } });
Loris 🐐
Loris πŸβ€’12mo ago
Okay, thank you !