main.js 911 B

12345678910111213141516171819202122232425262728293031323334353637
  1. require('dotenv').config();
  2. const {ShardingManager} = require('discord.js');
  3. const manager = new ShardingManager( './bot.js', {
  4. execArgv: ['--icu-data-dir=node_modules/full-icu'],
  5. shardArgs: ( process.argv[2] === 'debug' ? ['debug'] : [] ),
  6. token: process.env.token
  7. } );
  8. manager.on( 'shardCreate', shard => {
  9. console.log( `\n- Shard[${shard.id}]: Launched` );
  10. shard.on( 'spawn', message => {
  11. console.log( `- Shard[${shard.id}]: Spawned` );
  12. shard.send( {
  13. shard: {
  14. id: shard.id
  15. }
  16. } );
  17. } );
  18. shard.on( 'message', message => {
  19. if ( message === 'SIGKILL' ) {
  20. console.log( '\n- Killing all shards!\n\n' );
  21. manager.shards.forEach( shard => shard.kill() );
  22. }
  23. } );
  24. } );
  25. manager.spawn();
  26. async function graceful(signal) {
  27. console.log( '- ' + signal + ': Disabling respawn...' );
  28. manager.respawn = false;
  29. }
  30. process.once( 'SIGINT', graceful );
  31. process.once( 'SIGTERM', graceful );