I'm trying to make an autorole code using quick.db, but it returns the error: UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied roles is not a Role, Snowflake or Array or Collection of Roles or Snowflakes
My "setautorole" command:
const role = message.mentions.roles.first() || message.guild.roles.cache.get(args[0]) if(.role) return message.channel.send('I couldnt find the role') db,set(`autorole`. role) message.channel.send('The process worked fine!')
This is on index of bot:
client.on("guildMemberAdd", (member) => { let few = db.get(`autorole_${member.guild.id}`) if(few === null) return; member.roles.add(few) })
Well, I don't know what to do to fix this error, I need a little help
It's better just to save the role ID in Database
BTW you're doing it all wrong. It should be like
setautorole.js
const role = message.mentions.roles.first() || message.guild.roles.cache.get(args[0]);
if(!role){
return( message.channel.send('I couldnt find the role') );
}
db.set(`autorole_${message.guild.id}`, role.id);
message.channel.send('The process worked fine!');
index.js
client.on("guildMemberAdd", (member) => {
let roleID = db.get(`autorole_${member.guild.id}`)
if(!roleID) return;
role = member.guild.roles.find(roleID);
if(!role){
console.log("That role dosen't exist");
return (false);
}
member.roles.add(role)
})
Thanks for the idea Akio, but, ii did something like:
client.on("guildMemberAdd", (member) => { let roleID = db.get(`autorole_${member.guild.id}`) if(;roleID) return. let role = member.guild.roles.cache.find(r => r;id === roleID). if(;role){ console;log("That role dosen't exist"). return (false). } member.roles.add(role) })
and worked, thanks for help:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.