dolfies / discord.py-self

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

IndexError encountered in SelfCord’s _get_build_number function #626

Closed AkamePro closed 6 months ago

AkamePro commented 7 months ago

Summary

I’m using the SelfCord library in Python 3.11 and I’ve encountered an issue. When I try to run my bot with the bot.run(config["token"], log_handler=handler) command, I get an IndexError: list index out of range error.

Reproduction Steps

I’m using the SelfCord library in Python 3.11 and I’ve encountered an issue. When I try to run my bot with the bot.run(config["token"], log_handler=handler) command, I get an IndexError: list index out of range error.

The traceback indicates that the error originates from the _get_build_number function in selfcord\utils.py. Here’s the relevant part of the traceback:

File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\selfcord\utils.py", line 1480, in _get_build_number build_url = 'https://discord.com/assets/' + re.compile(r'assets/+([a-z0-9]+).js').findall(login_page)[-2] + '.js' IndexError: list index out of range

It seems like the regular expression re.compile(r'assets/+([a-z0-9]+).js').findall(login_page) is not finding enough matches in login_page, and when it tries to access the penultimate element with [-2], it throws an IndexError.

I’m not sure how to resolve this issue. Any help would be greatly appreciated. Thank you!

Code

Traceback (most recent call last):
  File "c:\Users\arnol\Desktop\KL-AKA.py", line 133, in <module>
    client.run("OTY2MTQzMzk0ODY0ODI4NDU3.G2o3GK.CuYcV61Ts7LE1pSlsf92yf6e3S5t-vrSkWbKPo")
  File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\selfcord\client.py", line 1059, in run
    asyncio.run(runner())
  File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\selfcord\client.py", line 1048, in runner
    await self.start(token, reconnect=reconnect)
  File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\selfcord\client.py", line 978, in start
    await self.login(token)
  File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\selfcord\client.py", line 820, in login
    data = await state.http.static_login(token.strip())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\selfcord\http.py", line 1054, in static_login
    data = await self.get_me()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\selfcord\http.py", line 698, in request
    await self.startup()
  File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\selfcord\http.py", line 634, in startup
    self.super_properties, self.encoded_super_properties = sp, _ = await utils._get_info(session)
                                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\selfcord\utils.py", line 1451, in _get_info
    bn = await _get_build_number(session)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\selfcord\utils.py", line 1480, in _get_build_number
    build_url = 'https://discord.com/assets/' + re.compile(r'assets/+([a-z0-9]+)\.js').findall(login_page)[-2] + '.js'
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^
IndexError: list index out of range

Expected Results

Que se ejecute sin problemas

Actual Results

No se inicia sesión

System Information

PS C:\Users\arnol> python -m discord -v Traceback (most recent call last): File "", line 189, in _run_module_as_main File "", line 148, in _get_module_details File "", line 112, in _get_module_details File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord__init.py", line 22, in from . import abc as abc, opus as opus, utils as utils File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\abc.py", line 62, in from .commands import ApplicationCommand, BaseCommand, SlashCommand, UserCommand, MessageCommand, _command_factory File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\init__.py", line 26, in from .context import * File "C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\context.py", line 30, in from discord.interactions import Interaction, InteractionMessage, InteractionResponse ImportError: cannot import name 'InteractionMessage' from 'discord.interactions' (C:\Users\arnol\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\interactions.py) PS C:\Users\arnol>

Checklist

Additional Information

No response

FrodoBaggyMcBaggins commented 7 months ago

I've been looking into this, but don't have time to make the PR.

The fix: 'assets/+([a-z0-9]+)\.js' in utils.py needs to include a period now, to 'assets/+([a-z0-9\.]+)\.js'

The HTML now has assets in the following format <script src="/assets/3726.e3e95df69f8cf8ff7aa8.js" defer

simoovara commented 6 months ago

by the way your user token is visible, should hide/change it asap (if you havent already)

FrodoBaggyMcBaggins commented 6 months ago

@AkamePro - your token is visible, as indicated above.

dolfies commented 6 months ago

Duplicate of #619