向特定用户添加角色

时间:2020-02-29 19:11:30

标签: javascript discord.js

我想向特定用户添加角色。 (使用CronJob作为If)

function one() {
client.users.get("1234").addRole("4321");
}

返回

TypeError: client.users.get(...).addRole is not a function
                                 ^

与guild.members尝试相同

2 个答案:

答案 0 :(得分:1)

您要授予角色的用户必须是GuildMember。您需要公会ID和用户ID:

from vpython import *
import math
import paho.mqtt.client as mqtt
import time

scene.title = "VPython: Draw a rotating cube"

scene.range = 2
scene.autocenter = True

def on_connect(client, userdata, flags, rc):
    global callback_on_connect
    print("Connected with result code "+str(rc))

    # Subscribing in on_connect() - if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe("CoreElectronics/test")#these two are topics; thus the client here listens to these two topics
    client.subscribe("CoreElectronics/topic")
    callback_on_connect=1

# The callback for when a PUBLISH message is received from the server.
#  ONLY WORKS IF YOU HAVE A MESSAGE FROM RASPBERRY PI SINCE IT IS A CALLBACK!
def on_message(client, userdata, msg):
    global yaw
    global pitch
    global roll
    global callback_on_message
    callback_on_message=1
    #print(msg.topic+" "+str(msg.payload))
    #print(float(msg.payload))
    #print(3)
    f=msg.payload
    angles = [float(i) for i in f.split()]
    #print(3)
    #type(angles)

    yaw=angles[0]
    pitch=angles[1]
    roll=angles[2]
    print(angles)
    #x = [float(i) for i in f.split()]
    #print(x[0])
    #print(x[1])
        # Do something else

print("Drag with right mousebutton to rotate view.")
print("Drag up+down with middle mousebutton to zoom.")

cube = box(pos=vec(0,0,0),length=1,height=0.1,width=1)    # using defaults, see http://www.vpython.org/contents/docs/defaults.html

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

print("Connecting to server...")
client.connect("mqtt.eclipse.org", 1883, 60)
print("Reached loop function...")
client.loop_start()

yaw=''
pitch=''
roll=''
yaw2=0
pitch2=0
roll2=0
#callback_on_connect=0
callback_on_message=0;

while callback_on_message==0:
    print("waiting for callback as a result of successful message receive", callback_on_message)
#now we are connected, can start taking in data
while True:      # Animation-loop
    try:
        #print("animating")
        #arrow(pos=vec(0,0,0),axis=vec(1,0,0))
        #arrow(pos=vec(0,0,0),axis=vec(0,1,0))
        #arrow(pos=vec(0,0,0),axis=vec(0,0,1))
        cube.rotate(angle=radians(yaw-yaw2), axis=vec(1,0,0),origin=vector(0,0,0))
        cube.rotate(angle=radians(pitch-pitch2), axis=vec(0,1,0),origin=vector(0,0,0))
        cube.rotate(angle=radians(roll-roll2), axis=vec(0,0,1),origin=vector(0,0,0))
        yaw2=yaw
        pitch2=pitch
        roll2=roll

    except KeyboardInterrupt:
        client.loop_stop()

    #cube.rotate( angle=yaw, axis=vec(1,0,0) )
    #cube.rotate( angle=pitch, axis=vec(0,1,0) )
    #cube.rotate( angle=roll, axis=vec(0,0,1) )

答案 1 :(得分:0)

感谢您的回答@Jakye,我能够这样做:

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

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

我正在使用Cron进行函数调用。