breqdev/flask-discord-interactions

Unhelpful error message for invalid interaction responses (e.g. using both ephemeral and embed)

dwilliamsuk opened this issue · 7 comments

Wondering if you could shed some light on this, when I specify that a command should be ephemeral by adding ephemeral=True I get a generic "This interaction failed" from discord and there are no errors spit out from python. Wondering if it still works for you with your example?

Here's my code resulting in "This interaction failed" when used with ephemeral=True

## Discord Slash Command Required Imports
from main import discord
from main import logger
from flask_discord_interactions import (Response,
                                        CommandOptionType)

@discord.command()
def info(ctx):
    "Bot Info"
    logger.info(f"/info ran by user '{ctx.author.id}' in guild '{ctx.guild_id}' with parameter(s) ''")
    return Response(ephemeral=True, embed={
            "author": {
                "name": "name",
                "icon_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
            },
            "fields": [
                {
                    "name": "Field 1",
                    "value": "Text"
                },
                {
                    "name": "Field 2",
                    "value": "Text"
                },
                {
                    "name": "Field 3",
                    "value": "Text"
                },
                {
                    "name": "Field 4",
                    "value": "Text"
                },
            ],
            })

It may look odd and that's because I use seperate py files for each command with my bot, it works fine without ephemeral=True

So, to be clear, there are no errors in Python, the request shows up in the Flask logs as a 200, but Discord shows an error message?

I noticed this exact behavior sometimes when I was testing out the new response types. I couldn't really figure out what was causing it.

I think what's happening is: Flask and my library receives the interaction from Discord, and returns a response fine (hence, there are no errors in Python). However, this response is somehow invalid, so when Discord receives it, it shows an error.

I thought I had solved this issue, but it looks like I need to do a bit more troubleshooting. I think Discord changed the way they parse responses, since things that used to work have stopped working for me.

Thanks for the detailed report! I'll try to look into this tonight if I have time, but I really can't promise anything--its hard to narrow down the issue because Discord doesn't give any information as to why the response is bad.

In the meantime, could you try a response that just includes content and doesn't include an embed? I don't think I've tested embeds in ephemeral responses, so there might be some weird behavior here (either on Discord's end or with my library) that I'm not aware of.

Yeah, there are no errors in python and request is logged as 200. Sure enough doing it without an embed makes the ephemeral response work correctly, very odd.

Here's the code that allowed for the ephemeral response to go through if you'd like to compare:

## Discord Slash Command Required Imports
from main import discord
from main import logger
from flask_discord_interactions import (Response,
                                        CommandOptionType)

@discord.command()
def test(ctx):
    "Bot Testing"
    logger.info(f"/test ran by user '{ctx.author.id}' in guild '{ctx.guild_id}' with parameter(s) ''")
    return Response("test", ephemeral=True)

@Breq16 Turns out you cant send ephemeral responses that are embeds, it's a discord problem and not the library see discord/discord-api-docs#2318

Oh, that makes sense. It's a shame Discord hasn't documented their API better. Thanks for your help with narrowing this down!

I'm going to reopen this issue, since I think the library should probably raise its own error here. It's not fun to debug problems like this, so now that we've figured out the root issue, I might as well add some code that verifies the response and shows a more helpful error message in the Python console. (No further action is required on your part--thanks for your report, and I'll try to work on this enhancement sometime soon!)

Fixed in d3e19b8.