discord-interactions.py

Common errors

What "This interaction failed", 10062, 40060, 50035 and 50013 mean, and how to fix them.

Most errors in an interactions bot come from three Discord rules: respond fast, respond once, send a valid message. This page starts from what you see and gives the fix in code.

Reading a Discord error#

When Discord rejects a call, discord.py raises a discord.HTTPException. Three pieces matter:

discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form BodyIn data.components.0.components.5: Must be 5 or fewer in length.
Piece Meaning
400 Bad Request HTTP status: 400 = invalid message, 403 = forbidden, 404 = not found
error code: 50035 Discord's code, more precise than the status
data.components.0.components.5 Where the problem is: 1st row (0), 6th component (5)

Indexes start at 0. Here the first row has a 6th button, while the limit is 5.

"This interaction failed"#

The red message under a button, a menu or a command. Discord received no response within 3 seconds.

Cause 1: the interaction never reaches your function.

@client.eventasync def on_interaction(interaction):    handled = await router.handle(interaction)    if not handled and interaction.type == discord.InteractionType.component:        print("No route for", interaction.data["custom_id"])

If that line prints, the ID in @router.on("...") does not match the component's custom_id: a typo, a capital letter, or an old message sent before you renamed the ID.

Cause 2: your function crashes before responding. The Python error shows in the bot's console, not in Discord. Look at the terminal.

Cause 3: your function is too slow. A database query, an external API or an AI call easily exceeds 3 seconds. Acknowledge first, answer later:

@router.on("report")async def report(interaction):    await defer_interaction(interaction, ephemeral=True)  # instant: "thinking…"    text = await build_report()  # can take up to 15 minutes    await send_followup(interaction, text, ephemeral=True)

For a slash command: await ctx.defer() then await ctx.respond(...), or directly @slash.command(auto_defer=True).

For a button that must edit its message: defer_interaction(interaction, update=True) then edit_original_response(interaction, ...).

10062: Unknown interaction#

discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

The response arrived after the 3 seconds: the interaction expired. Same fix as cause 3 above. If it happens while your code is fast, check that the same bot is not running twice (two instances fight over interactions).

40060: Interaction has already been acknowledged#

discord.errors.HTTPException: 400 Bad Request (error code: 40060): Interaction has already been acknowledged.

Your function responds twice to the same interaction. An interaction accepts one initial response; the next ones are followups.

# Wrong: two initial responsesawait respond_to_interaction(interaction, "Step 1")await respond_to_interaction(interaction, "Step 2")  # 40060 # Rightawait respond_to_interaction(interaction, "Step 1")await send_followup(interaction, "Step 2") # Even simpler: respond picks for youawait respond(interaction, "Step 1")await respond(interaction, "Step 2")

ctx.respond(...) in a slash command already does this: calling it twice is safe.

Another classic cause: two routers or two on_interaction handling the same click. Keep a single entry point.

50035: Invalid Form Body#

The message breaks one of Discord's limits. The In data... line says which. The most common:

Discord message Limit Fix
components.N.components: Must be 5 or fewer in length 5 buttons per row create_auto_rows(buttons)
components: Must be 5 or fewer in length 5 rows per message (outside V2) Pagination, or a menu instead of buttons
custom_id ... duplicated Unique custom_ids in a message Add data that tells them apart
label: Must be 80 or fewer in length 80 characters per button Shorten the text
options: Must be 25 or fewer in length 25 options per menu Several menus, or autocomplete
placeholder: Must be 150 or fewer in length 150 characters Shorten
content: Must be 2000 or fewer in length 2000 characters of text Split, or use a V2 container (4000)
value: This field is required Menu option without a value select_option("Text", "value")
The specified component type is invalid in this context Misplaced component (a button outside a row, a V2 component in a modal) Put buttons in create_action_row or .row()
Invalid emoji Unknown emoji, or from a server the bot is not in Unicode emoji, or "<:name:id>" from one of the bot's servers
Invalid Form Body on url Invalid URL (link button, image) Full https:// URL

50013: Missing Permissions#

discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

The bot is not allowed to do this in that channel. Common causes:

  • Giving a role: it needs "Manage Roles" and its role must be above the given role in the server role list.
  • Sending in a channel: a channel overwrite removes "Send Messages" from the bot.
  • Kicking or banning someone whose role is higher than the bot's.

Check before acting with @bot_has_permissions(...): the user then gets a clear message instead of a failure.

@slash.command(description="Give a role")@bot_has_permissions(manage_roles=True)async def give(ctx, member, role): ...

50001: Missing Access#

The bot cannot see the channel (no "View Channel" permission) or is no longer in the server.

Slash commands do not show up#

Situation Fix
Global commands never visible Invite the bot with the applications.commands scope in addition to bot
New command invisible Without default_guilds, global sync can take a while. During development: SlashManager(client, default_guilds=[SERVER_ID])
Command greyed out or missing for some users @default_permissions(...) hides it from members without the permission; server admins can also restrict it in Settings > Integrations
Old commands duplicated They were registered globally and on the server. Sync once without them, or remove them

Errors raised by the module#

These happen before sending, with a French message:

Error Cause
ValueError: custom_id trop long (…) data= too large for 100 characters
ValueError: Un bouton Premium demande sku_id style="premium" without sku_id
ValueError: Une section accepte 3 TextDisplay maximum More than 3 texts in section()
ValueError: Une section doit avoir un accessoire (bouton ou thumbnail) section(...) without .thumbnail(...) or .button(...)
ValueError: Une modale accepte 5 composants maximum More than 5 fields in ModalBuilder
ValueError: Les embeds sont interdits avec les composants V2 : utilise un container An embed= in a message that holds a container
ValueError: embed et embeds sont exclusifs embed= and embeds= together
TypeError: Destination non supportée send_message received something other than a channel, a member or a context

Slash command errors#

The module turns refusals into exceptions you can customise with @slash.on_error. Without a handler, the user gets an ephemeral English message.

errors.py
from discord_interactions.slash import (    BotMissingPermissions,    CheckFailure,    CommandOnCooldown,    InvalidOption,    MissingPermissions,    NotInGuild,)  @slash.on_errorasync def errors(ctx, error):    if isinstance(error, CommandOnCooldown):        message = f"Slow down: try again in {error.retry_after:.0f} s."    elif isinstance(error, MissingPermissions):        message = "You are missing: " + ", ".join(error.missing_permissions)    elif isinstance(error, BotMissingPermissions):        message = "I am missing: " + ", ".join(error.missing_permissions)    elif isinstance(error, NotInGuild):        message = "This command only works in a server."    elif isinstance(error, InvalidOption):        message = f"Invalid value: {error}"    elif isinstance(error, CheckFailure):        message = error.message    else:        return False  # unexpected error: default handling (log + generic message)    await ctx.respond(message, ephemeral=True)    return True

Returning False lets the module handle the error: it is logged with the full traceback, and the user sees a generic message.

See what happens#

Enable logs to follow every command and error in the console:

import logging logging.basicConfig(level=logging.INFO)logging.getLogger("discord_interactions").setLevel(logging.DEBUG)

Type a name: create_button, ModalBuilder, cooldown.