Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14360

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

$
0
0

I have added ephemeral commands in my discord bot using interaction.I am deferring the interaction at the first line of code to not terminate the commandHere is my code:

@commands.hybrid_command()async def hello(self, ctx: commands.Context[Any], *, link: str) -> None:    await ctx.interaction.response.defer()    await create_channel(ctx, "test channel")    channel_ctx: "MessageableChannel" = ctx.channel    response = "hello discord member"    await send_ephemeral_message(ctx=ctx, response=response)

This is my function to send ephemeral message:

async def send_ephemeral_message(ctx, response):"""This function will check if the message is an interaction and if it is, it will send an ephemeral message.    Used to send normal message in testing environment."""    ctx = ctx if ctx and isinstance(ctx, commands.Context) else None    interaction = ctx.interaction if ctx else None    print('context', ctx and interaction)    if ctx and interaction:        await interaction.followup.send(response, ephemeral=True)        print('ephemeral message sent')    # send non-ephemeral message in testing environment    else:        await ctx.send(response)

Sometimes I am getting this error:

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

while sometimes i get this error:

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

How can i fix this?


Viewing all articles
Browse latest Browse all 14360

Trending Articles