Discord.js-删除所有以*开头的角色(星号)

时间:2020-04-05 11:46:15

标签: javascript discord discord.js

我需要执行一个命令,该命令首先从星号开头的所有角色中删除该成员,然后分配一个将在命令参数中传递的角色。

exports.run = (client, message, [where]) => {
    var role = message.guild.roles.cache.find(role => role.name === where);

    if (role && where.substring(0, 1) == '*') {
        //remove all roles that start with * from the member, probably some kind of for loop?

        message.member.roles.add(role);
        message.channel.send(message.member.nickname + ' entered the channel ' + where + '.');
    }
    else message.channel.send('Channel' + where + ' does not exist or does not start with *.');
};

您能帮我解决这个问题吗?谢谢。

1 个答案:

答案 0 :(得分:1)

您的解决方案是:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public static int movespeed = 6;
    public Vector3 userDirection = Vector3.right;

    public Rigidbody rb;

    public bool isGrounded;

    Vector3 jumpMovement;

    bool jump = false;

    [SerializeField]
    float jumpHeight = 1.8f, jumpSpeed = 8f;

    void Start()
    {
        rb = GetComponent<Rigidbody>();    }


    void OnCollisionStay()
    {
        isGrounded = true;
    }

    public float fallMultiplier = 3.5f;
    public float lowJumpMultiplier = 2f;


    void Update()
    {
        //movement
        transform.Translate(userDirection * movespeed * Time.deltaTime);

        if (Input.GetButton("Jump") && !jump)
            StartCoroutine(Jump());
    }


    IEnumerator Jump()
    {
        float originalHeight = transform.position.y;
        float maxHeight = originalHeight + jumpHeight;
        jump = true;
        yield return null;

        while (transform.position.y < maxHeight)
        {
            transform.position += transform.up * Time.deltaTime * jumpSpeed;
            yield return null;
        }

        while (transform.position.y > originalHeight)
        {
            transform.position -= transform.up * Time.deltaTime * jumpSpeed;
            yield return null;
        }

        rb.useGravity = true;
        jump = false;

        yield return null;

    }
}