Ad
Bot Not Adding Role In Raw Event
I'm not able to give the user who has reacted any role.
The bot should give the person who is reacting a certain role, but every time I react, it throws an error:
TypeError: Cannot read property 'addRole' of undefined
This is the code:
bot.on("raw", event => {
if (event.t == "MESSAGE_REACTION_ADD" || event.t == "MESSAGE_REACTION_REMOVE") {
if (event.d.message_id === "527150993033527296") {
if (event.d.user_id !== bot.user.id) {
if (event.d.emoji.id === "527129359895625728") {
var myRole = "525279851247173644";
defRole(myRole);
}
function defRole() {
if (event.t === "MESSAGE_REACTION_ADD") {
event.d.user_id.guild.addRole(myRole);
var myRole;
} else {
var myRole;
}
}
}
}
}
});
Ad
Answer
git it working with this code:
bot.on("raw", event => {
if (event.t == "MESSAGE_REACTION_ADD" || event.t == "MESSAGE_REACTION_REMOVE") {
if (event.d.message_id === "529692171234705418") { //ID of Message where the Reaction is added
if (event.d.user_id !== bot.user.id) {
let reaction = event.d.emoji.id;
if (reaction === "527129359895625728") { // Reaction Emoji ID
var myRole = "525279851247173644"; // Role Id
defRole(myRole);
}
function defRole() {
const myGuilds = bot.guilds.get(event.d.guild_id);
if (event.t === "MESSAGE_REACTION_ADD") {
myGuilds.fetchMember(event.d.user_id).then(member => member.addRole(myGuilds.roles.get(myRole))).catch(console.error);
}
else {
myGuilds.fetchMember(event.d.user_id).then(member => member.removeRole(myGuilds.roles.get(myRole))).catch(console.error);
}
}
}
}
}
});
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad