Closed FightMan01 closed 3 years ago
Fixed on 1ba7404bd1b167a2145cfe332720ab6a34daa8da but not released
Well it did not fix for me. I installed this lib yesterday using pip install git+https://github.com/kiki7000/discord.py-components.git
But I made some modifications for example to always add a listener even I turn change_discord_methods to False. Somehow if I turn that to True my bot slows down but when I turn it to False the performance will be normal. Also I reworked the on_socket_response a bit when I tried. to investigate the issue but I don't think that's important. https://github.com/FightMan01/discord.py-components/commit/b3a44dd4a772cb87b7d167f58e0ee212eea0a89d
Was the ping lower when the previous version?
No, the ping was very high even in the version 0.5.2.4
I mean on version 0.5.1 and lower
I didn't try that. I just tried the PyPi version and the GitHub version.
Did you try with add_listener
disabled?
Well, the on_button_click event is very important for me, so I didn't do that.
Oh, that is not related to add_listener
.
That is for users who are using discord-py-slash-command
Oh :D But I'm using discord-py-slash-command as well 😅
Oh Could you try it?
Well yes, but I noticed one more thing with interaction.respond()
.
When I used it, the roundtrip was about 1200ms
. So I decided to write the request myself:
#await res.respond(type=InteractionType.UpdateMessage, embed=embed, content=None)
token = res.interaction_token
compid = res.interaction_id
data = {}
data["content"] = None
embeds = [embed]
if embeds:
embeds = list(map(lambda x: x.to_dict(), embeds))
data["embeds"] = embeds
async with aiohttp.ClientSession() as session:
await session.post(f"https://discord.com/api/v8/interactions/{compid}/{token}/callback", json={"type": InteractionType.UpdateMessage, "data": data})
And I noticed with this I get about 310ms
which is acceptable in Hungary.
To be honest I don't really understand what cause this problem.
Could you replace
async with aiohttp.ClientSession() as session:
await session.post(f"https://discord.com/api/v8/interactions/{compid}/{token}/callback", json={"type": InteractionType.UpdateMessage, "data": data})
in you code with
bot.http.request(discord.http.Route("POST", f"/interactions/{compid}/{token}/callback"), json={"type": InteractionType.UpdateMessage, "data": data})
Hmm, about 300ms
I use this formula:
t1 = time.perf_counter()
await self.client.http.request(discord.http.Route("POST", f"/interactions/{compid}/{token}/callback"), json={"type": InteractionType.UpdateMessage, "data": data})
t2 = time.perf_counter()
print(f"Latency: {round((t2-t1)*1000)}ms")
But it's still thinking a lot and sometimes fail with this: discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction
Ok, I managed to figure out something. I made another bot client and added it only 1 server. And it works very fast and fine. Same code, same environment, same everything but a different bot client. My main bot is over 8000 servers. Maybe that is the "problem"?
But your bot's ping was fine until you used this library
Yes, so that's why this is very confusing for me
Bug Line
Excpected Action
Actual Action
Reproducing the action
Possible Solution
Environment
Check