Issue
I have an issue with sending messages to a discord channel.
If the channel is in timeout due to discord channel cooldown, then the channel.send(msg)
function will block. Is there any way to find the remaining time the cooldown has left or check if the send()
function will be executed without blocking, before the actual function call?
# this.channels is an array of objects type discord.TextChannel, API reference: https://discordpy.readthedocs.io/en/stable/api.html#textchannel
for l_channel in this.channels:
await l_channel.send(l_msg.text) # Blocks if channel is in cooldown due to slow mode, any way to check before sending?
await asyncio.sleep(2)
Solution
Solved by modifying the discord library:
- open http.py inside discord's module folder and replace
if r.status == 429:
if not r.headers.get('Via'):
# Banned by Cloudflare more than likely.
raise HTTPException(r, data)
on line 213, with:
if r.status == 429:
if not r.headers.get('Via') or data["code"] == 20016: # Or is in slow mode
# Banned by Cloudflare more than likely.
raise HTTPException(r, data)
This will cause an exception to be thrown that you can catch and the channel.send()
function will not block.
Answered By - David Hožič
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.