dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
684 stars 162 forks source link

In application_id: Value "None" is not snowflake. #247

Closed TheOnlyWayUp closed 2 years ago

TheOnlyWayUp commented 2 years ago

Summary

Application ID in interaction payload is None

Code -

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix=commands.when_mentioned, self_bot=True)    
channelId = 939844090969858078
gameChoice = 19

@bot.event
async def on_ready():
    print("Ready!")
    channel = await bot.fetch_channel(channelId)
    await channel.send("pls stream")
    resp = await bot.wait_for("message", check=lambda m: m.author.id == 270904126974590976)
    print(f"\n-\n{resp}\n-\n{resp.components}\n-\n{resp.jump_url}\n-\n")
    await resp.components[0].children[0].click()
    resp = await bot.wait_for("message_edit", check=lambda m, a: a.channel.id == channelId)
    resp = resp[1]
    print(f'\n-\n{resp.components[0].children[0].options}\n-\n')
    await resp.components[0].children[0].choose(resp.components[0].children[0].options[gameChoice])
    await resp.components[1].children[0].click()

bot.run(TOKEN)

Inspiration.

Error -

Ignoring exception in on_ready
Traceback (most recent call last):
  File "C:\Users\aboud\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 329, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\aboud\Desktop\lol.py", line 19, in on_ready
    await resp.components[0].children[0].choose(resp.components[0].children[0].options[gameChoice])
  File "C:\Users\aboud\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\components.py", line 366, in choose
    await state.http.interact(payload)
  File "C:\Users\aboud\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\http.py", line 397, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In application_id: Value "None" is not snowflake.

Works after modifying Line 348 of components.py to include application ID.

This issue was also present with Buttons (#178), [Line 231 of components.py](), it was fixed by adding 'application_id': str(message.application_id or message.author.id), The current value of line 348 is 'application_id': str(message.application_id),, hence I propose a similar fix be used here too.

Made on behalf of @Sxvxgee.

Thanks for all the work Dolfies :)

Additional Information

Using commit 0f2dda9dd4392039576243a27fc34f7ab9542e2e.

theAbdoSabbagh commented 2 years ago

I'm able to reproduce the error if necessary!

TheOnlyWayUp commented 2 years ago

Fixed in #248.

dolfies commented 2 years ago

This is fixed in the upstream merge (interactions are getting a small refactor because modals).