Without a clear statement of the issue or what is working and not working, I will make an educated guess based on some key points in your code.
It seems like you are trying to access properties of a variable called message
, however, you have not defined or set this variable in your provided code. It is possible that you actually want to reference the message to which a reaction has been added. In order to achieve this, you should utilize the MessageReaction
parameter available in the messageReactionAdd
event as reaction
.
To correct this, replace instances of message.<something>
with
reaction.message.<something>
throughout your code snippet.
Furthermore, adding the role Alerts directly to message.member
may not have the desired outcome, as it would assign the Alerts role to the author of the original message rather than the user who reacted. To address this issue, you need to first locate the member in the guild corresponding to the reacting user and then assign them the Alerts role. This involves utilizing the User
object and identifying the appropriate Member
, as roles can only be added to Member objects. Below is a code snippet to guide you in the right direction:
// Obtain and store the guild (server) where the message was sent.
const guild = reaction.message.guild;
const memberWhoReacted = guild.members.find(member => member.id === user.id);
memberWhoReacted.addRole(role);