【问题标题】:interact with discord using requests in python在 python 中使用请求与不和谐进行交互
【发布时间】:2023-03-19 23:28:01
【问题描述】:

我正在尝试使用请求和 python 自动单击不和谐按钮,但是当我发送请求时出现错误。

discord buttons

我试过了:

header = {
        'authorization' : 'XXX'
}    

data = {
        "type": 3,
        "guild_id": "XXX",
        "channel_id": "XXX",
        "message_id": message['id'],
        "application_id": "XXX",
        "data": {
                "component_type": 2,
                "custom_id": message['components'][0]['components'][1]['custom_id']
        }
}

try:
        r = requests.post('https://discord.com/api/v9/interactions', data = data, headers = header)

但程序最后给了我:

{"code": 50035, "errors": {"data": {"_errors": [{"code": "MODEL_FROM_NON_DICTLIKE", "message": "模型只能从类似 dict 的东西中实例化, got "}]}}, "message": "Invalid Form Body"}

如果您有任何想法可以帮助我,我很感兴趣。 谢谢。

【问题讨论】:

  • "custom_id": message['components'][0]['components'][1]['custom_id'] 有错误你可以 print() 和 print(type()) 吗?
  • message 是一个字符串,但将 data = data 更改为 json = data 就可以了!谢谢;)
  • Lmao 这帮助我终于按下了按钮!谢谢@yurrickx_

标签: python python-requests discord bots


【解决方案1】:

尝试将data = data 更改为json = data

【讨论】:

  • 非常感谢!它正在工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-13
  • 1970-01-01
  • 2021-10-18
  • 1970-01-01
相关资源
最近更新 更多