File tree Expand file tree Collapse file tree 5 files changed +72
-5
lines changed Expand file tree Collapse file tree 5 files changed +72
-5
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " discord.js-advanced-command-handler" ,
3- "version" : " 2.2 .0" ,
3+ "version" : " 3.1 .0" ,
44 "description" : " 🤖 Discord.js V14 Command and Event Handler" ,
55 "main" : " src/index.js" ,
66 "type" : " module" ,
2222 },
2323 "dependencies" : {
2424 "chalk" : " ^5.1.2" ,
25- "discord.js" : " ^14.9.0"
25+ "discord.js" : " ^14.9.0" ,
26+ "node-cron" : " ^3.0.2"
2627 }
2728}
Original file line number Diff line number Diff line change 1+ export default {
2+ cron : '*/15 * * * * *' ,
3+ async execute ( client ) {
4+ let activityList = [
5+ `with ${ client . guilds . cache . size } servers` ,
6+ `with ${ client . users . cache . size } users` ,
7+ `with ${ client . channels . cache . size } channels` ,
8+ `with ${ client . emojis . cache . size } emojis` ,
9+ ] ;
10+
11+ let activity = activityList [ Math . floor ( Math . random ( ) * activityList . length ) ] ;
12+ client . user . setActivity ( activity , {
13+ name : activity ,
14+ type : 1
15+ } ) ;
16+ }
17+ } ;
Original file line number Diff line number Diff line change 1+ import fs from 'fs' ;
2+ import cron from 'node-cron' ;
3+ import chalk from 'chalk' ;
4+
5+ export async function loadCronJobs ( folderPath , client ) {
6+ let files = fs . readdirSync ( folderPath ) ;
7+
8+ for ( let i = 0 ; i < files . length ; i ++ ) {
9+ folderPath = folderPath . replace ( 'src/' , '' ) ;
10+ let cronjob = await import ( `../${ folderPath } /${ files [ i ] } ` ) ;
11+ cron . schedule ( cronjob . default . cron , ( ) => cronjob . default . execute ( client ) ) ;
12+ console . log ( chalk . greenBright ( `[CRONJOB] Loaded ${ ( chalk . yellow ( files [ i ] ) ) } ` ) ) ;
13+ }
14+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import config from './data/config.js';
44import loadEvents from './handlers/events.js' ;
55import loadInteractions from './handlers/handler.js' ;
66import registerApplicationCommands from './handlers/application.js' ;
7+ import { loadCronJobs } from './handlers/cronjobs.js' ;
78
89const client = new Discord . Client ( {
910 intents : [
@@ -28,6 +29,7 @@ client.interaction = new Discord.Collection();
2829await loadEvents ( client ) ;
2930await loadInteractions ( './src/interactions' , client ) ;
3031await registerApplicationCommands ( client ) ;
32+ await loadCronJobs ( './src/cron' , client ) ;
3133
3234process . on ( 'uncaughtException' , function ( err ) {
3335 console . error ( err ) ;
You can’t perform that action at this time.
0 commit comments