SHARE
TWEET

Untitled

a guest Sep 20th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var discord = require('discord.js');
  2. var fs = require('fs');
  3. var randomColour = require('randomcolor');
  4. var Discord = require('discord.js');
  5. var client = new Discord.Client();
  6. var Config = require('./config.json');
  7.  
  8. client.on('ready', () => {
  9.    client.user.setGame('bármi');
  10. });
  11.  
  12. class Bot {
  13.     constructor(){
  14.         this.servers = require('./servers.json');
  15.         this.discordClient = new discord.Client({sync: true});
  16.        
  17.         this.discordClient.on("ready", () => {this.initialize();});
  18.        
  19.         this.discordClient.on("message", (msg) => {this.processMessage(msg)});
  20.        
  21.         this.discordClient.login(Config.discord_token);
  22.     }
  23.    
  24.     initialize() {
  25.         this.log("CCsatlakozott a  discordhoz.");
  26.        
  27.         setInterval(() => {
  28.             this.randomizeRoleColors();
  29.         }, Config.randomize_delay*1000);
  30.     }
  31.    
  32.     processMessage(msg) {
  33.         if(msg.content.startsWith(".multicolor")) {
  34.             for(var role of msg.mentions.roles.array()) {
  35.                 msg.reply("A " + role + " nevezetü rang mostantól szinváltósra van állitva");
  36.                
  37.                 this.addRainbowRole(msg.guild.id, role.id);
  38.             }
  39.         }
  40.     }
  41.    
  42.     randomizeRoleColors() {
  43.         for(var server in this.servers) {
  44.             var liveGuild = this.discordClient.guilds.get(server);
  45.            
  46.             if (!liveGuild) {
  47.                 this.error("Guild with ID " + server+ " no longer exists or the bot has been removed from it.");
  48.                 continue;
  49.             }
  50.            
  51.             for(var role of this.servers[server]) {
  52.                 var liveRole = liveGuild.roles.get(role);
  53.                
  54.                 liveRole.setColor(randomColour(), "Rainbowbot random role color randomizer.");
  55.             }
  56.         }
  57.     }
  58.    
  59.     addRainbowRole(guild, role) {
  60.         if(this.servers[guild] == undefined) {
  61.             this.servers[guild] = [];
  62.         }
  63.        
  64.         for(var existingRole of this.servers[guild]) {
  65.             if(existingRole == role) {
  66.                 return "A rang hozzá lett adva";
  67.             }
  68.         }
  69.        
  70.         this.servers[guild].push(role);
  71.         this.saveServers();
  72.     }
  73.    
  74.     saveServers() {
  75.         fs.writeFileSync("./servers.json", JSON.stringify(this.servers), "utf8");
  76.         this.log("A szerver el lett mentve");
  77.     }
  78.    
  79.     log(message) {
  80.         console.log("\x1b[32mINFO\x1b[37m - \x1b[0m" + message);
  81.     }
  82.    
  83.     error(message) {
  84.         console.log("\x1b[31mERROR\x1b[37m - \x1b[0m" + message);
  85.     }
  86. }
  87.  
  88. var instance = new Bot();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top