Python不协调OAuth2错误请求(Guild.Join)

2024-04-19 13:05:18 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我正在尝试使用Discord的API向我的公会添加一个用户

我使用的范围是公会。加入,识别和公会identify%20guilds%20guilds.join

URL是https://discordapp.com/api

这是我的密码:

@staticmethod
    def add_to_guild(access_token, userID):
        url = f"https://discordapp.com/api/guilds/{guildId that I cant show}/members/{userID}"

        botToken = "<Bot Token I can't SHow haha>"

        headers = {
            "Authorization" : f"Bot {botToken}",
            'Content-Type': 'application/json'
        }

        payload = {
            'access_token' : access_token
        }

        response = requests.put(url=url, data=payload, headers=headers)
        print(response.text)

调用此方法时,我收到以下错误:

{"message": "400: Bad Request", "code": 0}

我已经翻阅了无数次Discord的文档,在互联网上搜索也无济于事

有人能帮忙吗?谢谢


Tags: httpscomtokenapiurlaccessresponsebot
1条回答
网友
1楼 · 发布于 2024-04-19 13:05:18

您必须将data替换为json

    def add_to_guild(access_token, userID):
        print(userID)
        url = f"{Oauth.discord_api_url}/guilds/<GuildID>/members/{userID}"

        headers = {
            "Authorization" : "Bot <bottoken>",
            "Content-Type": "application/json"
        }

        payload = {
            'access_token' : str(access_token)
        }

        response = requests.put(url=url, json=payload, headers=headers)
        print(response.text)

相关问题 更多 >