Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js");
  2. const client = new Discord.Client();
  3. const token = '';
  4.  
  5. client.login(token);
  6.  
  7. // initialize bot
  8. client.on('ready', () => {
  9.     console.log(`Logged in as ${client.user.username}`);
  10.     // send a bjr. the main function of the bot
  11.     let hasBjr = false;
  12.     setInterval(() => {
  13.         let today = new Date();
  14.         if ((!today.dst() && today.getHours() === 12) || (today.dst() && today.getHours() === 11)) {
  15.             if (!hasBjr) {
  16.                 hasBjr = true;
  17.                 for (let [k, v] of client.channels) {
  18.                     if ((v instanceof Discord.TextChannel) && v.permissionsFor(client.user).hasPermission("SEND_MESSAGES")) {
  19.                         v.sendMessage('bjr')
  20.                         .then(console.log('Sent bjr on ' + today.toString()))
  21.                         .catch(console.error);
  22.                     }
  23.                 }
  24.             }
  25.         } else {
  26.             hasBjr = false;
  27.         }
  28.     }, 999);
  29.  
  30. });
  31.  
  32. // take commands here
  33. client.on('message', (msg) => {
  34.     if (msg.content.toUpperCase() === '!BJR') {
  35.         msg.channel.sendMessage('bjr');
  36.     }
  37. });
  38.  
  39. // date stuff
  40. Date.prototype.stdTimezoneOffset = function() {
  41.     let jan = new Date(this.getFullYear(), 0, 1);
  42.     let jul = new Date(this.getFullYear(), 6, 1);
  43.     return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
  44. }
  45.  
  46. Date.prototype.dst = function() {
  47.     return this.getTimezoneOffset() < this.stdTimezoneOffset();
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement