简体   繁体   English

Webhook 状态代码 400:{“embeds”:[“长度必须为 10 或更少。”]}

[英]Webhook status code 400: {"embeds": ["Must be 10 or fewer in length."]}

I´m developing a bot that sends messages to the discord channel every second, however when I run the program and only sent 10 messages and after only print [1/1] Webhook status code 400: {"embeds": ["Must be 10 or fewer in length."]}.我正在开发一个每秒向 discord 通道发送消息的机器人,但是当我运行程序并且仅发送 10 条消息并且仅打印[1/1] Webhook 状态代码 400 之后:{“embeds”:[“必须是长度为 10 或更少。"]}。 I don't find why is this happening, I'm using discord_webhook library and python to do this.我不知道为什么会发生这种情况,我正在使用 discord_webhook 库和 python 来执行此操作。 Here is my code这是我的代码

async def __scrape_api(session, pid):
    async with session.get(API_URL + pid) as response:
        data = await response.json()
        print(f"scrape {data}")
        if not __search_product(pid):
            name = data["name"]
            image_url = data['skus'][0]['image']
            for size in data['skus']:
                if size['available']:
                    print("sent")
                    message = DiscordEmbed(title=f'{name}', url=f'{PRODUCT_URL_0}{size["sku"]}{PRODUCT_URL_1}',
                                           description=f'talla: {size["dimensions"]["Tallas Calzado"]}\nPrecio: {size["bestPriceFormated"]}')
                    message.set_thumbnail(url=image_url)
                    message.set_timestamp()
                    webhook.add_embed(message)
                    response = webhook.execute()
                    time.sleep(1)
            # save to database
            __insert_new_product(pid, name, image_url, data['available'])

I found the solution for this after few minutes of taking a deeper look inside it's code.在深入了解其代码几分钟后,我找到了解决方案。 Basically each embed you send over is being held in the webhook object, once you made 10 requests with embeds then it gives you that error.基本上,您发送的每个嵌入都保存在 webhook object 中,一旦您使用嵌入发出 10 个请求,就会出现该错误。 All you have to do is:你所要做的就是:

webhook.execute(remove_embeds=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM