Shorten max page size in [p]slash list to account for box size #6167

Merged
AAA3A-AAA3A merged 1 commit from pathch-10 into V3/develop 2023-06-19 14:02:33 +02:00
AAA3A-AAA3A commented 2023-05-19 18:52:15 +02:00 (Migrated from github.com)

Description of the changes

Hello,

If a bot has a lot of slash commands, as the page size only takes into account the formatting with the py language (shorted_by=8), the pages can be more than 2000 characters long and the sending of the message fails. This PR fixes this problem.

Thanks in advance,
AAA3A

Traceback (most recent call last):
  File "{USERPROFILE}\redenv\Lib\site-packages\discord\ext\commands\core.py", line 229, in wrapped
    ret = await coro(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "{USERPROFILE}\Documents\GitHub\Red-DiscordBot\redbot\core\core_commands.py", line 2334, in slash_list
    await menu(ctx, pages)
  File "{USERPROFILE}\Documents\GitHub\Red-DiscordBot\redbot\core\utils\menus.py", line 141, in menu
    await view.start(ctx)
  File "{USERPROFILE}\Documents\GitHub\Red-DiscordBot\redbot\core\utils\views.py", line 239, in start
    self.message = await ctx.send(**kwargs, ephemeral=ephemeral)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "{USERPROFILE}\Documents\GitHub\Red-DiscordBot\redbot\core\commands\context.py", line 91, in send
    return await super().send(content=content, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "{USERPROFILE}\redenv\Lib\site-packages\discord\ext\commands\context.py", line 1016, in send
    return await super().send(
           ^^^^^^^^^^^^^^^^^^^
  File "{USERPROFILE}\redenv\Lib\site-packages\discord\abc.py", line 1561, in send
    data = await state.http.send_message(channel.id, params=params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "{USERPROFILE}\redenv\Lib\site-packages\discord\http.py", line 744, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In content: Must be 2000 or fewer in length.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "{USERPROFILE}\redenv\Lib\site-packages\discord\ext\commands\bot.py", line 1350, in invoke
    await ctx.command.invoke(ctx)
  File "{USERPROFILE}\Documents\GitHub\Red-DiscordBot\redbot\core\commands\commands.py", line 791, in invoke
    await super().invoke(ctx)
  File "{USERPROFILE}\redenv\Lib\site-packages\discord\ext\commands\core.py", line 1642, in invoke
    await ctx.invoked_subcommand.invoke(ctx)
  File "{USERPROFILE}\redenv\Lib\site-packages\discord\ext\commands\core.py", line 1023, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "{USERPROFILE}\redenv\Lib\site-packages\discord\ext\commands\core.py", line 238, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In content: Must be 2000 or fewer in length.

Have the changes in this PR been tested?

Yes

### Description of the changes Hello, If a bot has a lot of slash commands, as the page size only takes into account the formatting with the `py` language (`shorted_by=8`), the pages can be more than 2000 characters long and the sending of the message fails. This PR fixes this problem. Thanks in advance, AAA3A ``` Traceback (most recent call last): File "{USERPROFILE}\redenv\Lib\site-packages\discord\ext\commands\core.py", line 229, in wrapped ret = await coro(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "{USERPROFILE}\Documents\GitHub\Red-DiscordBot\redbot\core\core_commands.py", line 2334, in slash_list await menu(ctx, pages) File "{USERPROFILE}\Documents\GitHub\Red-DiscordBot\redbot\core\utils\menus.py", line 141, in menu await view.start(ctx) File "{USERPROFILE}\Documents\GitHub\Red-DiscordBot\redbot\core\utils\views.py", line 239, in start self.message = await ctx.send(**kwargs, ephemeral=ephemeral) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "{USERPROFILE}\Documents\GitHub\Red-DiscordBot\redbot\core\commands\context.py", line 91, in send return await super().send(content=content, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "{USERPROFILE}\redenv\Lib\site-packages\discord\ext\commands\context.py", line 1016, in send return await super().send( ^^^^^^^^^^^^^^^^^^^ File "{USERPROFILE}\redenv\Lib\site-packages\discord\abc.py", line 1561, in send data = await state.http.send_message(channel.id, params=params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "{USERPROFILE}\redenv\Lib\site-packages\discord\http.py", line 744, in request raise HTTPException(response, data) discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body In content: Must be 2000 or fewer in length. The above exception was the direct cause of the following exception: Traceback (most recent call last): File "{USERPROFILE}\redenv\Lib\site-packages\discord\ext\commands\bot.py", line 1350, in invoke await ctx.command.invoke(ctx) File "{USERPROFILE}\Documents\GitHub\Red-DiscordBot\redbot\core\commands\commands.py", line 791, in invoke await super().invoke(ctx) File "{USERPROFILE}\redenv\Lib\site-packages\discord\ext\commands\core.py", line 1642, in invoke await ctx.invoked_subcommand.invoke(ctx) File "{USERPROFILE}\redenv\Lib\site-packages\discord\ext\commands\core.py", line 1023, in invoke await injected(*ctx.args, **ctx.kwargs) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "{USERPROFILE}\redenv\Lib\site-packages\discord\ext\commands\core.py", line 238, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body In content: Must be 2000 or fewer in length. ``` ### Have the changes in this PR been tested? <!-- Choose one (remove the line that doesn't apply): --> Yes <!-- If the question doesn't apply (for example, it's not a code change), choose Yes. Please respond to this question truthfully. We do not delay nor reject PRs based on the answer to this question but it allows to better review this PR. -->
Jackenmen (Migrated from github.com) approved these changes 2023-06-19 14:02:19 +02:00
Jackenmen (Migrated from github.com) left a comment

Looks good, thanks for your contribution!

Looks good, thanks for your contribution! ![](https://i.fluffy.cc/4HrdmGw7MHL3rcH3J0lCBBG7xhlxnWs7.gif)
Sign in to join this conversation.
No reviewers
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!6167
No description provided.