Answer the question
In order to leave comments, you need to log in
find doesn't work, why?
I am writing a bot in Node JS. After entering the person of the team, a request is made to the site, after which the site sends the role that needs to be set, after which I try to look for the role in the array of discord roles, but it writes an error that this is not a function.
Mistake:
index.js:143
let role = message.channel.guild.roles.find(c => c.name === request.responseText)
^
TypeError: message.channel.guild.roles.find is not a function
at exports.XMLHttpRequest.request.onload (E:\Projects\Discord Bot\index.js:143:56)
at exports.XMLHttpRequest.dispatchEvent (E:\Projects\Discord Bot\node_modules\xmlhttprequest\lib\XMLHttpRequest.js:591:25)
at setState (E:\Projects\Discord Bot\node_modules\xmlhttprequest\lib\XMLHttpRequest.js:614:14)
at IncomingMessage.<anonymous> (E:\Projects\Discord Bot\node_modules\xmlhttprequest\lib\XMLHttpRequest.js:447:13)
at IncomingMessage.emit (events.js:322:22)
at endReadableNT (_stream_readable.js:1187:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
client.on('message', message => {
if (message.author === client.user) return;
let result = [message.content.split(' ', 1).toString(), message.content.split(' ').slice(1).join(' ')];
var prefix = prefixarr[prefixarr.indexOf(message.content.charAt(0))]
if (message.content.startsWith(prefix + 'auth')) {
var request = new XMLHttpRequest();
request.open('POST', "https://api.novostroi.org/metrostroi/discord/auth", true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.send("id=" + message.author.id + "&token=" + result[1])
message.delete()
request.onload = function() {
console.log(request.responseText);
if (request.status == 200) {
let role = message.guild.roles.find(c => c.name === request.responseText)
let user = message.mentions.members.first();
user.addRole(role.id);
const embed = new MessageEmbed()
.setTitle("Аккаунт подключен")
.setDescription("Аккаунт подключен к вашей учётной записи Discord.")
.setFooter("Сообщение удалится через 10 секунд.", false)
message.channel.send(embed);
} else {
message.channel.send('Неверный SteamID');
}
};
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question