简体   繁体   English

为特定用户添加角色

[英]Adding a role to a specific user

I want to add a role to a specific user.我想为特定用户添加角色。 (using CronJob as an If) (使用 CronJob 作为 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对 guild.members 进行了同样的尝试

The user you want to give a role to must be a GuildMember.您要为其分配角色的用户必须是 GuildMember。 You need the guild ID and the user ID:您需要公会 ID 和用户 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:感谢您的回答@Jakye,我能够这样做:

let guild = client.guilds.get("111");
let user = guild.members.get("222");

function one() {
user.addRole("333");
}

I'm using Cron for function call.我正在使用 Cron 进行函数调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM