中途http请求INTERACTION_APPLICATION N_COMMAND_INVALID_VERSION

问题描述 投票:0回答:1

我使用discord.py创建了一个Discord机器人来发送HTTP请求并调用MidJourney的斜线命令来使用/imagine创建图像。我前一段时间发现了这个代码片段,它一直有效到今天。

def PassPromptToSelfBot(prompt : str):
    payload ={"type":2,"application_id":"936929561302675456","guild_id":Globals.SERVER_ID,
              "channel_id":Globals.CHANNEL_ID,"session_id":"2fb980f65e5c9a77c96ca01f2c242cf6",
              "data":{"version":"1077969938624553050","id":"938956540159881230","name":"imagine","type":1,"options":[{"type":3,"name":"prompt","value":prompt}],
                      "application_command":{"id":"938956540159881230",
                                             "application_id":"936929561302675456",
                                             "version":"1077969938624553050",
                                             "default_permission":True,
                                             "default_member_permissions":None,
                                             "type":1,"nsfw":False,"name":"imagine","description":"Create images with Midjourney",
                                             "dm_permission":True,
                                             "options":[{"type":3,"name":"prompt","description":"The prompt to imagine","required":True}]},
              "attachments":[]}}
    

    header = {
        'authorization' : Globals.SALAI_TOKEN
    }
    response = requests.post("https://discord.com/api/v9/interactions",
    json = payload, headers = header)
    return response

但是,现在我收到此错误消息:{“code”:50035,“errors”:{“data”:{“_errors”:[{“code”:“INTERACTION_APPLICATION_COMMAND_INVALID_VERSION”,“message”:“Dieser Befehl ist veraltet, bitte versuche es in einigen Minuten erneut."}]}}, "message": "无效的表单正文"}

如果有人知道更新后的版本值或如何计算出来,我将不胜感激。该代码段的源代码存储库位于:https://github.com/Wildric-Auric/MidJourney-Wrapper

python discord discord.js discord.py httprequest
1个回答
0
投票

您可以通过执行 POST 来获取新版本的命令

https://discord.com/api/v10/channels/<channelid>/application-commands/search?type=1&include_applications=true&query=<command_name>

这是最新的 /imagine 命令数据

https://discord.com/api/v10/channels/<channel_id>/application-commands/search?type=1&include_applications=true&query=imagine

{
    "applications": [
        {
            "id": "936929561302675456",
            "name": "Midjourney Bot",
            "icon": "f6ce562a6b4979c4b1cbc5b436d3be76",
            "description": "Generate an image based on a text prompt in under 60 seconds using the </imagine:938956540159881230> command!\n\nhttps://docs.midjourney.com/docs/terms-of-service",
            "summary": "",
            "type": null,
            "bot": {
                "id": "936929561302675456",
                "username": "Midjourney Bot",
                "global_name": null,
                "avatar": "f6ce562a6b4979c4b1cbc5b436d3be76",
                "discriminator": "9282",
                "public_flags": 589824,
                "bot": true,
                "avatar_decoration_data": null
            }
        }
    ],
    "application_commands": [
        {
            "id": "938956540159881230",
            "application_id": "936929561302675456",
            "version": "1118961510123847772",
            "default_member_permissions": null,
            "type": 1,
            "nsfw": false,
            "name": "imagine",
            "description": "Create images with Midjourney",
            "dm_permission": true,
            "contexts": [
                0,
                1,
                2
            ],
            "integration_types": [
                0
            ],
            "options": [
                {
                    "type": 3,
                    "name": "prompt",
                    "description": "The prompt to imagine",
                    "required": true
                }
            ]
        }
    ],
    "cursor": {
        "previous": null,
        "next": null,
        "repaired": false
    }
}

您可以在应用程序启动时执行一次并将其缓存。

参见命令信息

© www.soinside.com 2019 - 2024. All rights reserved.