Answer the question
In order to leave comments, you need to log in
TypeError: Cannot read property 'guild' of undefined?
An error is thrown
(node:17712) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'guild' of undefined
at Client. (C:\Users\kuchm\Desktop\DSTBOT\index.js:224:27)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
( node:17712 ) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_reje... ). (rejection id: 1)
(node:17712) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
client.on('messageReactionAdd', async (reaction, user,message) => {
if (reaction.partial) {
try {
await reaction.fetch();
} catch (error) {
console.error('Something went wrong when fetching the message: ', error);
return;
}
}
console.log(`${reaction.message.author}'s message "${reaction.message.content}" gained a reaction!`);
console.log(`${reaction.count} user(s) have given the same reaction to this message!`);
var role1 = message.guild.roles.cache.find(role => role.id === "786640140440567849");
guild.addRole(role1);
if(reaction.message.content == 'Поставь реакцию если не бот'){
}
});
Answer the question
In order to leave comments, you need to log in
1 . the event messageReactionAdd
takes only two parameters - messageReaction (the reaction object) and user (the user who put the reaction on the message) - the message parameter does not exist.
if you want to get the Message class, you should use reaction.message...
2. as I understand it, the error is in the value of the role1 variable - it is solved by adding reaction.
before the message
.
tip : use .get()
to get something by ID, and .find()
- to search by name / color, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question