discord-py-ui / discord-ui

A discord.py extension for sending, receiving and handling ui interactions in discord
https://discord-ui.rtfd.io/
MIT License
36 stars 9 forks source link

ctx.author.send() gives a 404 "Unknown Channel" error #94

Closed tiltowait closed 2 years ago

tiltowait commented 2 years ago

When using discord-ui, any attempt to perform an await ctx.author.send(...) results in the following error:

File "/opt/homebrew/lib/python3.9/site-packages/discord_ui/override.py", line 50, in send
    r = await self._state.http.request(route, json=payload)
  File "/opt/homebrew/lib/python3.9/site-packages/discord/http.py", line 250, in request
    raise NotFound(r, data)
discord.errors.NotFound: 404 Not Found (error code: 10003): Unknown Channel

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

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/homebrew/lib/python3.9/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NotFound: 404 Not Found (error code: 10003): Unknown Channel

Currently, I'm working around it by manually creating a DM channel, but it's an ugly kludge.

RedstoneZockt commented 2 years ago

Fixed in 4.2.4

tiltowait commented 2 years ago

Unfortunately, this seems only partially fixed as of 4.2.6.

I have the following user interaction flow that occurs in DMs:

  1. User messages bot in public server
  2. Bot opens DM and sends user a message with components (SelectMenu)
  3. User selects component
  4. Bot deletes original message
  5. Go to step 2; repeat until done

Steps 1-3 all work fine. The bot sends the message in the DM, and the user is able to select the component, which the bot sees. However, at step 4, I get the Unknown Channel error above. This error only occurs if I use ctx.author.send() in step 2. If I create a DM channel in step 2, then step 4 finishes correctly, and the loop proceeds.

If it matters (only mentioning this because the example code all uses them), I am not using slash commands.

RedstoneZockt commented 2 years ago

I will look at it. Thanks for reporting 😃

kvsxxx commented 2 years ago

sorry for the issues, this is fixed in v4.2.7

tiltowait commented 2 years ago

Sorry, but I'm still experiencing the error even in v4.2.7. Referring to my flow above, it now successfully completes step 4; however, upon executing step 5 (return to step 2), I get the same error as before.

I have written a trivial example that generates the Unknown Channel error. This fails consistently on my end when using discord-ui but not when using vanilla discord.py.

cached_ctx = None

@bot.command()
async def test_test(ctx):
    global cached_ctx
    if cached_ctx is None:
        cached_ctx = ctx
        await cached_ctx.author.send("Hi") # OK
    else:
        await cached_ctx.author.send("Bye") # Should work but generates error

Thanks for the work so far! We're getting closer.

discord-ui 4.2.7 discord.py 1.7.3 python 3.9.6

kvsxxx commented 2 years ago

aight thanks for your patience, this should hopefully finally be fixed in v4.2.8

tiltowait commented 2 years ago

It works now. Thanks for the quick work.