Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src.bing_chat.response -> 400 Bad Request (error code: 50035): Invalid Form Body In components.0.components.2.label: Must be 80 or fewer in length. #153

Closed
CatfishGG opened this issue May 10, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@CatfishGG
Copy link

The following error is what I'm getting this time,

Traceback (most recent call last):
  File "/workspaces/DiscordBot-EdgeGPT/src/bing_chat/response.py", line 162, in send_message
    await interaction.followup.send(response, view=ButtonView(conversation_style_str, suggest_responses, user_chatbot), embed=link_embed)
  File "/home/codespace/.local/lib/python3.10/site-packages/discord/webhook/async_.py", line 1805, in send
    data = await adapter.execute_webhook(
  File "/home/codespace/.local/lib/python3.10/site-packages/discord/webhook/async_.py", line 221, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In components.0.components.2.label: Must be 80 or fewer in length.

It tells me that the response is probably too long to be displayed? I guess it must be 80 or fewer in length eh? is it possible to get a fix for this?

@FuseFairy
Copy link
Owner

ok, change src\bing_chat\button_view.py file like this:

import discord
from ..log import setup_logger
from functools import partial

logger = setup_logger(__name__)

# To add suggest responses
class ButtonView(discord.ui.View):
    def __init__(self, conversation_style_str:str=None, suggest_responses:list=None, user_chatbot=None, images:list=None):
        super().__init__(timeout=120)

        if images:
            for i, image in enumerate(images, start=1):
                if i > 2:
                    self.add_item(discord.ui.Button(label=f"Link {i}", url=image, row=2))
                else:
                    self.add_item(discord.ui.Button(label=f"Link {i}", url=image, row=1))

        if conversation_style_str and suggest_responses and user_chatbot:
            # Add buttons
            for label in suggest_responses:
                label = label[:78] + "..." if len(label) > 80 else label
                button = discord.ui.Button(label=label, row=3)
                # Button event
                async def callback(interaction: discord.Interaction, button: discord.ui.Button):     
                    await interaction.response.defer(ephemeral=False, thinking=True)
                    username = str(interaction.user)
                    usermessage = button.label
                    channel = str(interaction.channel)
                    logger.info(f"\x1b[31m{username}\x1b[0m : '{usermessage}' ({channel}) [Style: {conversation_style_str}] [button]")
                    await user_chatbot.send_message(message=usermessage, interaction=interaction)
                self.add_item(button)
                self.children[-1].callback = partial(callback, button=button)

@FuseFairy FuseFairy added the bug Something isn't working label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants