Why I can not send discord message using python-requests on Replit?

53 Views Asked by At

I can not send discord message using python-requests on Replit anymore and i dont know what happened. I remember the last time it still worked on Replit is 03/10/2023. What should I do? Here is my simple code:

import requests

url = “https://discord.com/api/v9/channels/<channel_id>/messages”
headers = {
“Authorization”: “<my_token>”,
“Content-Type”: “application/json”
}
data = {
“content”: “Hello, World!”
}

response = requests.post(url, headers=headers, json=data)

I have try that code on Visual Studio Code on my laptop and it still working but when using on Replit, it dont have any error but the message on discord channel not appear

1

There are 1 best solutions below

1
On BEST ANSWER

With the added information that you're getting a "429 Client Error: Too many Requests" error this is easier to solve.

The problem is that services like replit typically run your code either on their services or through some proxy on their systems. As a result your IP address when running code on replit is likely shared by many other users. This will trip the ratelimiting software used by some services, and apparently discord is one of those services.