[英]TypeError: Cannot read property 'add' of undefined, Discord.JS
client.on('message', message => {
if (message.content.startsWith(prefix + 'sanitar')) {
if (message.member.hasPermission('ADMINISTRATOR')) {
const user = message.mentions.users.first();
if (user != undefined) {
user.GuildMemberRoleManager.add(635602511964667907);
message.channel.send(`<:mebel:632608605635608578> | Пользователь ${user} был отправлен в дурку ебать!`);
} else {
message.channel.send('<:mebel:632608605635608578> | Пингани кого-то, идиот.');
message.channel.send('<:debil:691052950998482955>');
}
} else {
message.channel.send('<:mebel:632608605635608578> | У вас недостаточно прав для этого действия!');
}
}
});
I'm trying to create an add-role command for my discord.js bot, but when it gets to user.GuildMemberRoleManager.add(635602511964667907);
我正在尝试为我的 discord.js 机器人创建一个添加角色命令,但是当它到达
user.GuildMemberRoleManager.add(635602511964667907);
i get:我得到:
TypeError: Cannot read property 'add' of undefined.
TypeError:无法读取未定义的属性“添加”。
I also tried to use user.Addrole
function, but i get:我也尝试使用
user.Addrole
function,但我得到:
user.Addrole is not a function.
user.Addrole 不是 function。
Maybe addrole is outdated now, idk.也许 addrole 现在已经过时了,idk。 I am very tired of this, so can somebody help me to fix it pls...
我对此感到非常厌倦,所以有人可以帮我解决它吗...
You need to use roles
not GuildMemberRoleManager
since roles
returns GuildMemberRoleManager
of the GuildMember
.您需要使用
roles
而不是GuildMemberRoleManager
,因为roles
返回GuildMemberRoleManager
的GuildMember
。
Also User
does not have roles
only GuildMember
does so you have to replace const user = message.mentions.users.first();
此外,
User
没有roles
,只有GuildMember
有,所以你必须替换const user = message.mentions.users.first();
with const user = message.mentions.members.first();
with
const user = message.mentions.members.first();
You also need to pass the role ID as a string, not a number.您还需要将角色 ID 作为字符串而不是数字传递。
user.roles.add('635602511964667907');
Also, you are correct, addRole()
is not a function and has deprecated since discord.js v12.另外,您是对的,
addRole()
不是 function 并且自 discord.js v12 以来已弃用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.