[Python] How to give a user a role in a discord server using Discord API endpoints and python...

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to provide a user with a role using Discord API Endpoints and python requests library

    I have tried using the function below to give a user a role in my discord server using the Discord API Guild endpoint as seen:

    def give_role(guild_id,user_id,role_id):
    url = f"https://discord.com/api/guilds/{guild_id}/members/{user_id}/roles/{role_id}"

    data = {
    "type": 4,
    "data": {
    }
    }
    response = requests.put(url, json=data)
    print(response)


    I get "<Response [401]>" from the print(response) function. I am expecting to get a "<Response[204]>" message and the user to be given the role

    Continue reading...

Compartilhe esta Página