Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require("discord.js");
- const client = new Discord.Client();
- const token = '';
- client.login(token);
- // initialize bot
- client.on('ready', () => {
- console.log(`Logged in as ${client.user.username}`);
- // send a bjr. the main function of the bot
- let hasBjr = false;
- setInterval(() => {
- let today = new Date();
- if ((!today.dst() && today.getHours() === 12) || (today.dst() && today.getHours() === 11)) {
- if (!hasBjr) {
- hasBjr = true;
- for (let [k, v] of client.channels) {
- if ((v instanceof Discord.TextChannel) && v.permissionsFor(client.user).hasPermission("SEND_MESSAGES")) {
- v.sendMessage('bjr')
- .then(console.log('Sent bjr on ' + today.toString()))
- .catch(console.error);
- }
- }
- }
- } else {
- hasBjr = false;
- }
- }, 999);
- });
- // take commands here
- client.on('message', (msg) => {
- if (msg.content.toUpperCase() === '!BJR') {
- msg.channel.sendMessage('bjr');
- }
- });
- // date stuff
- Date.prototype.stdTimezoneOffset = function() {
- let jan = new Date(this.getFullYear(), 0, 1);
- let jul = new Date(this.getFullYear(), 6, 1);
- return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
- }
- Date.prototype.dst = function() {
- return this.getTimezoneOffset() < this.stdTimezoneOffset();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement