discordbot / pingpong.py
joytou's picture
Update pingpong.py
4800093 verified
raw
history blame contribute delete
764 Bytes
from datetime import datetime
from threading import Timer
import time
import requests
import os
# ๆฏ้š”4ๅˆ†้’Ÿๅ‘้€ping
def sendPingTask():
Timer(240, sendPing, ()).start()
def sendPing():
print("sendPing")
url = os.environ.get("WEBHOOK_URL")
headers = {
"Content-Type": "application/json"
}
payload = {
"content": "ping"
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200 or response.status_code == 204:
print("Message ping sent successfully")
sendPingTask()
else:
print(f"Failed to send message ping: {response.status_code}")
def run():
sendPingTask()
sendPing()
def pingpong():
print("Running pingpong")
run()