I started making a command, where the message author should get the role after entering the command. But I always get the error for "Cannot read property of 'add' of undefined".
Code:
case 'ticket':
if(!message.channel.id === "757221433335218216") return;
if (message.channel.id === "757221433335218216"){
var randomRole = Math.random()
const person = message.author
var roleCreator = message.guild.roles.create({
data: {
name: randomRole.toLocaleString(),
color: "#ff0000",
permissions: 0
}
}).then(role => {
person.roles.add(roleCreator)
});
break;
.add()
you will need GuildMember not a Usercase 'ticket':
if(!message.channel.id === "757221433335218216") return;
if (message.channel.id === "757221433335218216"){
var randomRole = Math.random()
const person = message.member //<< Here, get the author as an GuildMember instead of getting author as an User
var roleCreator = message.guild.roles.create({
data: {
name: randomRole.toLocaleString(),
color: "#ff0000",
permissions: 0
}
}).then(role => {
person.roles.add(role) // <<Here, passing role instead of roleceator
});
break;
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.