Skip to content

Instantly share code, notes, and snippets.

@iamnotacoder-djs
Last active January 4, 2022 22:49
Show Gist options
  • Save iamnotacoder-djs/ba0a43ba37b8d6b19d71184eec14b93b to your computer and use it in GitHub Desktop.
Save iamnotacoder-djs/ba0a43ba37b8d6b19d71184eec14b93b to your computer and use it in GitHub Desktop.
Rainbow-Role Bot
// Константы - Либы
const Discord = require('discord.js');
const client = new Discord.Client();
const config = require("./config.json"); // Константы
const wait = require('util').promisify(setTimeout);
const r_size = 7;
const r_colors = new Array(r_size);
var r_place = 0;
//const r_colors = ["#DF5050","#5087DF","#313131","#FFFFFF"];
const guild = client.guilds.first();
client.on("ready", () => {
// когда бот подключился к серверам discord
for (var i=0; i < r_size; i++) {
var red = sin_to_hex(i, 0 * Math.PI * 2/3); // 0 deg
var blue = sin_to_hex(i, 1 * Math.PI * 2/3); // 120 deg
var green = sin_to_hex(i, 2 * Math.PI * 2/3); // 240 deg
r_colors[i] = '#'+ red + green + blue;
}
client.setTimeout(checkTime, 60 * 1000);
});
function checkTime() {
// тут код
var role = guild.roles.get("id");
if (role != undefined) {
role.setColor(r_colors[r_place])
.catch(console.log);
if (r_place == (r_colors.length - 1)) {
r_place = 0;
} else {
r_place++;
}
}
client.setTimeout(checkTime, 60 * 1000);
}
function sin_to_hex(i, phase) {
var sin = Math.sin(Math.PI / r_colors.length * 2 * i + phase);
var int = Math.floor(sin * 127) + 128;
var hex = int.toString(16);
return hex.length === 1 ? '0'+hex : hex;
}
@Fixrain
Copy link

Fixrain commented Jan 17, 2021

ddddd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment