-
-
Notifications
You must be signed in to change notification settings - Fork 14
Question for "Event Setup" #71
-
For the eventsPath and related documentation, I am having trouble making my file immediately run, upon startup without an event listener shown in the docs being triggered. Will show below my normal setup, with a regular command handler. What would I need to make this work with CommandKit in TS by chance? Thank you for your time and efforts.
const { Events } = require('discord.js'); module.exports = { name: Events.ClientReady, once: true, execute(client) { console.log('Immediately runs w/o anything triggered'); // Looking to have this work with CommandKit. }, };
Beta Was this translation helpful? Give feedback.
All reactions
Hello.
I'm a bit confused when you mention "immediately run". Do you want to:
- Have some code run without any event (including "ready") be triggered.
- Have some code run when the bot has started up.
Here's how you can achieve both of the above:
For 1:
To run code without any event being triggered (including "ready"), CommandKit doesn't really provide any way to handle this situation since it's out of the scope of handling commands/events with Discord.js. You can achieve this pretty easily however by placing your code anywhere before logging in to your client/bot.
// File: src/index.ts // ... rest of your code function main() { console.log('This will run immediately when the app starts...
Replies: 1 comment 1 reply
-
Hello.
I'm a bit confused when you mention "immediately run". Do you want to:
- Have some code run without any event (including "ready") be triggered.
- Have some code run when the bot has started up.
Here's how you can achieve both of the above:
For 1:
To run code without any event being triggered (including "ready"), CommandKit doesn't really provide any way to handle this situation since it's out of the scope of handling commands/events with Discord.js. You can achieve this pretty easily however by placing your code anywhere before logging in to your client/bot.
// File: src/index.ts // ... rest of your code function main() { console.log('This will run immediately when the app starts without waiting for the bot to start up'); } main(); client.login('your-token-here');
For 2:
To run code immediately after your bot has gone online, you can make use of the "ready" event provided by Discord.js. If you're trying to handle this event using CommandKit:
- Create a folder inside your "events" folder with the name of the event - in this case it's "ready".
- Inside the new "ready" folder, create a file (you can name it anything you want) that will export a default function:
// File: src/events/ready/on-startup.ts import type { Client } from 'discord.js'; export default function (client: Client<true>) { console.log('This will run immediately after the bot has gone online'); }
Let me know if this solves your issue.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Thank you for your reply. The second option you displayed, was the solution for me.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1