Не могу понять как избавиться от ошибки TypeError: fn.bind is not a function discord.js
Вот есть код:
const Discord = require('discord.js');
const client = new Discord.Client();
const config = require('./config.json');
const size = config.colors;
const rainbow = new Array(size);
for (let i = 0; i < size; i++) {
const red = sin_to_hex(i, 0 * Math.PI * 2 / 3); // 0 deg
const blue = sin_to_hex(i, 1 * Math.PI * 2 / 3); // 120 deg
const green = sin_to_hex(i, 2 * Math.PI * 2 / 3); // 240 deg
rainbow[i] = '#' + red + green + blue;
}
function sin_to_hex(i, phase) {
const sin = Math.sin(Math.PI / size * 2 * i + phase);
const int = Math.floor(sin * 127) + 128;
const hex = int.toString(16);
return hex.length === 1 ? '0' + hex : hex;
}
let place = 0;
const servers = config.servers;
function changeColor() {
for (let index = 0; index < servers.length; ++index) {
client.guilds.cache.get(servers[index]).roles.cache.find('name', config.roleName).setColor(rainbow[place])
.catch(console.error);
if (config.logging) {
console.log(`[ColorChanger] Changed color to ${rainbow[place]} in server: ${servers[index]}`);
}
if (place == (size - 1)) {
place = 0;
} else {
place++;
}
}
}
client.on('ready', () => {
console.log(`Logged in as ${client.user.username}!`);
if (config.speed < 10) {
console.log("The minimum speed is 60.000, if this gets abused your bot might get IP-banned");
process.exit(1);
}
setInterval(changeColor, config.speed);
});
client.login(config.token);
И он выдаёт ошибку:
TypeError: fn.bind is not a function
at Map.find (D:\Code\FirstBot\node_modules@discordjs\collection\dist\index.js:158:21)
at Timeout.changeColor [as _onTimeout] (D:\Code\FirstBot\rainbow.js:29:55)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
Я без понятия как это решить, поможете мне пожалуйста?
Ответы (1 шт):
Автор решения: Grundy
→ Ссылка
Первым параметром find должна быть функция. В примере в вопросе передается строка.
Так как у строки нет метода bind и получается указанная ошибка.