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ā€¢2y 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ā€¢2y 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ā€¢2y 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 šŸOPā€¢2y 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ā€¢2y 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 šŸOPā€¢2y ago
Okay, thank you !
Want results from more Discord servers?
Add your server