【问题标题】:Python Discord OAuth2 - Bad Request (Guild.Join)Python Discord OAuth2 - 错误请求(Guild.Join)
【发布时间】:2020-12-05 05:48:35
【问题描述】:

您好,我正在尝试使用 Discord 的 API 将用户添加到我的公会。

我使用的范围是 Guild.Join、Identify 和 Guilds。 identify%20guilds%20guilds.join

网址是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 的文档,并在互联网上搜索无济于事。

有人可以帮忙吗?谢谢。

【问题讨论】:

  • 我正在查看文档(tbh,我已经有一段时间没有这样做了,我忘记了很多),但是您是否仔细检查过该机器人是否具有适当的权限加人?
  • @downwithocp 是的。
  • 我的下一个想法是检查用户 id 变量是否正确命名/调用。 discordpy.readthedocs.io/en/latest/api.html#discord.User

标签: python oauth-2.0 discord


【解决方案1】:

您必须将 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)

【讨论】:

    猜你喜欢
    • 2020-12-04
    • 2015-11-03
    • 2017-06-04
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 2018-07-04
    • 2020-04-22
    • 1970-01-01
    相关资源
    最近更新 更多