简体   繁体   中英

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."]}. I don't find why is this happening, I'm using discord_webhook library and python to do this. 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. All you have to do is:

webhook.execute(remove_embeds=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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