我正在尝试为标记游戏做一个机器人。我正在这样做,所以您可以提及一个用户,并向他们添加“ IT”角色,但是当他们没有提及成员时,它就会添加到他们中。
我的代码在这里:
< / p>
const args = message.content.slice(prefix.length).trim().split(/ +/g);
if (message.content.startsWith(`${prefix}tag`)) {
if (!message.mentions.users.size) {
let roleenter = message.guild.roles.get("555947490315075600");
let member = message.member;
member.addRole(roleenter).catch(console.error);
message.reply("you are now it!")
client.channels.get("555943069271457792").send(member + " is now in!")
await message.guild.fetchMembers();
const role = message.guild.roles.get("555947490315075600");
for (const member of role.members.array()) {
await member.removeRole(role);
}} else {
let member = message.mentions.users.first();
let roleenter = message.guild.roles.get("555947490315075600");
member.addRole(roleenter).catch(console.error);
message.reply("you are now it!")
client.channels.get("555943069271457792").send(member + " is now in!")
await message.guild.fetchMembers();
const role = message.guild.roles.get("555947490315075600");
for (const member of role.members.array()) {
await member.removeRole(role);
每当我尝试#tag @user时,它在我较早使用它时便会显示member.addRole is not a function
,并且有效。
答案 0 :(得分:1)
更改此行:
let member = message.mentions.users.first();
此行:
let member = message.mentions.members.first();
您使用了提到的用户的user对象,但是您必须使用guildMember对象,因为您无法为用户分配角色。