Fix Discord Bot Component Custom ID Length Exceeding 100 Characters
🔍 WiseChecker

Fix Discord Bot Component Custom ID Length Exceeding 100 Characters

When building interactive Discord bots with buttons, select menus, or other components, you may encounter an error where the custom ID exceeds 100 characters. This limit is enforced by Discord’s API. If your bot sends a component with a custom ID longer than 100 characters, Discord rejects the message and returns an error. This article explains why this limit exists, how to check your custom IDs, and how to fix the issue by shortening or restructuring them.

Key Takeaways: Fixing Discord Bot Component Custom ID Length

  • Custom ID max length: Discord enforces a hard limit of 100 characters for component custom IDs.
  • Use short, meaningful IDs: Keep custom IDs under 100 characters by using abbreviations or structured prefixes.
  • Store extra data elsewhere: Move complex data to a database or use state keys instead of encoding everything in the custom ID.

ADVERTISEMENT

Why Discord Limits Custom IDs to 100 Characters

Discord requires every interactive component such as buttons, select menus, and text inputs to have a unique custom ID. This ID is a string that your bot uses to identify which component was interacted with when a user clicks or selects an option.

The 100-character limit is a hard cap set by Discord’s API. If you send a component with a custom ID longer than 100 characters, the API returns an error and the message is not sent. This prevents performance issues and ensures that component IDs remain manageable for both Discord and bot developers.

Common causes of exceeding the limit include:

  • Encoding user IDs, message IDs, or other large numbers directly in the custom ID
  • Using long, descriptive strings like delete_message_from_user_123456789_in_channel_987654321
  • Storing entire JSON objects or serialized data inside the custom ID

Understanding this limit helps you design your bot’s interaction system to avoid errors and keep code clean.

Steps to Fix Custom ID Length Errors

Follow these steps to identify and fix custom IDs that exceed 100 characters. These steps apply to any Discord bot library that uses components, such as discord.py, discord.js, or Discordeno.

  1. Check your bot’s error logs
    Look for an error message similar to HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body or custom_id: Must be 100 or fewer in length. This confirms the custom ID is too long.
  2. Find the component with the long custom ID
    Search your code for all places where you define custom IDs for buttons, select menus, or other components. Use your editor’s search function to find strings passed as custom_id or id.
  3. Measure the length of each custom ID
    In your code, add a temporary check to print the length of every custom ID before sending the component. For example, in Python: print(len(custom_id)). In JavaScript: console.log(customId.length). Run the bot and trigger the component to see which IDs exceed 100.
  4. Shorten the custom ID
    Replace long, descriptive strings with short abbreviations. For instance, change delete_message_from_user_123456789 to del_123456789. Use a maximum of 10-20 characters for the prefix and keep the total under 100.
  5. Use a database or state store for extra data
    If you need to associate a component with complex data such as a user ID, message ID, and a specific action, store that data in a database or in-memory store. Use a short key as the custom ID, and look up the details when the interaction is received. For example, store button_click_1 in the database with the full details.
  6. Test the fix
    After shortening or restructuring the custom ID, restart your bot and test the component. Attempt to click the button or select an option. The error should no longer appear, and the interaction should work as expected.

ADVERTISEMENT

If the Error Persists After Shortening

If you have shortened all custom IDs but the error still occurs, check for other causes.

Multiple Components with the Same Custom ID

Discord allows multiple components to share the same custom ID, but if you have more than 100 components in a single message, you might hit a different rate limit. However, the 100-character limit applies per component. Ensure you are checking each individual custom ID length, not the total number of components.

Select Menu Option Values

Select menus have both a custom ID for the menu itself and a value for each option. The option value is also limited to 100 characters. If you are storing long strings in select menu option values, shorten them as well or use a database lookup.

Text Input Component Custom IDs

Text input components within modals also have a custom ID limit of 100 characters. Apply the same shortening techniques to modal text inputs.

Using an Outdated Library

Some older versions of bot libraries may not properly validate custom ID length before sending, leading to unexpected errors. Update your library to the latest version to get better error messages and validation.

Custom ID Design Strategies: Short vs Long

Item Short Custom ID Long Custom ID
Description Uses abbreviations and minimal data Includes full context in the string
Example del_123 delete_message_from_user_123456789_in_channel_987654321
Length Under 100 characters Exceeds 100 characters
Requires external storage Yes, often needs a database or state No, but hits limit
Performance Faster to parse and send Slower and causes errors

When designing custom IDs, always aim for short IDs under 100 characters. Use a consistent prefix like btn_, sel_, or modal_ followed by a short unique identifier. Store any additional context in a database or a dictionary keyed by that identifier. This approach keeps your code maintainable and avoids the 100-character limit entirely.

By following these steps, you can fix the custom ID length error and ensure your bot’s interactive components work reliably. After fixing, test all components that use custom IDs, especially those that were previously failing. Consider adding a validation function in your code that checks custom ID length before sending, so future errors are caught early. This practice saves debugging time and keeps your bot stable.

ADVERTISEMENT