【问题标题】:how do I send an API request to interact with a discord bot如何发送 API 请求以与不和谐机器人交互
【发布时间】:2022-01-19 07:26:41
【问题描述】:
header = {
    'authorization': TOKEN
}

payload = {
        'message_id': message_id['id'],
        'data': {'component_type': 2, 'custom_id': ids[1]}
    }

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

到目前为止我的代码

得到错误--

"{\"code\": 50035, \"errors\": {\"application_id\": {\"_errors\": [{\"code\": \"BASE_TYPE_REQUIRED\", \"message\": \"This field is required\"}]}, \"channel_id\": {\"_errors\": [{\"code\": \"BASE_TYPE_REQUIRED\", \"message\": \"This field is required\"}]}, \"type\": {\"_errors\": [{\"code\": \"BASE_TYPE_REQUIRED\", \"message\": \"This field is required\"}]}}, \"message\": \"Invalid Form Body\"}"

请帮助我如何解决此问题并发送 api 请求以与机器人交互。

【问题讨论】:

  • 也许你可以多解释一下你的代码。我真的不知道你在做什么/你想要实现什么样的 API 请求。
  • 这是 discord.py 吗?我不认识那个代码。如果您使用的是叉子,请标记该叉子

标签: python json python-requests discord.py discord-interactions


【解决方案1】:

您正在尝试从头开始使用 API,这比已经为您完成的库更困难且效率更低。也许你应该使用NextcordPyCord 之类的(因为discord.py 已被弃用),除非你有理由不这样做。

【讨论】:

    猜你喜欢
    • 2020-10-01
    • 1970-01-01
    • 2021-10-16
    • 2018-08-05
    • 1970-01-01
    • 2021-02-12
    • 2023-03-19
    • 2021-08-07
    • 1970-01-01
    相关资源
    最近更新 更多