Reputation: 11
I want to add a role to a specific user. (using CronJob as an If)
function one() {
client.users.get("1234").addRole("4321");
}
returns
TypeError: client.users.get(...).addRole is not a function
^
tried the same with guild.members
Upvotes: 1
Views: 159
Reputation: 11
Thanks for your Answer @Jakye, I was able to do it as this:
let guild = client.guilds.get("111");
let user = guild.members.get("222");
function one() {
user.addRole("333");
}
I'm using Cron for function call.
Upvotes: 0
Reputation: 6625
The user you want to give a role to must be a GuildMember. You need the guild ID and the user ID:
let Guild = Client.guilds.get("613844301042024503");
let User = Guild.members.get("223750026654908419");
let Role = Guild.roles.get("615244847468642307");
if (User) { // Checking if the user is a member of the guild.
User.addRole(Role);
} else {
return message.channel.send("Couldn't do that. | The user is not a memer of the guild.");
}
Upvotes: 1