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
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.");
}
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.
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.