我开始制作命令,消息作者在输入命令后应获得该角色。但是我总是收到“无法读取未定义'add'的属性”的错误。
代码:
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;
答案 0 :(得分:1)
.add()
,您需要GuildMember而不是用户case '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;