Issue
I am using python discord API https://discordpy.readthedocs.io/en/latest/api.html and I would like to have a forever loop(like a while loop) That checks with function whether on the site is a new content(I have already wrote a scraper). In other words: if scraper sees a new post it will return a value(link). I want to connect it with discord and when there is an output of that function, it will be sent to the text channel. I have completely no clue how to do that. The scraper function is asynchronous. All that comes to my mind is to make a second thread and log in and then message manually through selenium
Solution
Use webhooks.
Create a webhook then whenever your scraper gets new data, submit a POST request to the webhook url you created with the content parameter set to your data.
Example:
import requests
WEBHOOK_URL = "https://discordapp.com/api/webhooks/123456789/qWerRYtyuqwfq" # Example webhook url
def sendToDiscord(webhookUrl, data):
return requests.post(webhookUrl, json={'content': data})
data = myScraper.get_data() # Whenever there is data from your scraper
sendToDiscord(WEBHOOK_URL, data) # Send it to Discord
Note: You can format your message, add images etc... by using the appropriate params
Answered By - FluidLight
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.