import time
import requests
def main():
webhook_url = input("Enter the Discord webhook URL: ").strip()
message = input("Enter the message to be sent: ").strip()
interval = input("Enter the interval between messages (seconds): ").strip()
# Validate the input
try:
interval = float(interval)
if interval < 1:
print("Interval is too short; setting it to 1 second to prevent spam.")
interval = 1
except ValueError:
print("Invalid interval value. Setting to 5 seconds by default.")
interval = 5
if not webhook_url.startswith("https://discord.com/api/webhooks/"):
print("Invalid webhook URL. Make sure it's a valid Discord webhook URL.")
return
if not message:
print("Message cannot be empty.")
return
print(f"Starting to send messages every {interval} seconds. Press Ctrl+C to stop.")
try:
while True:
data = {
"content": message
}
response = requests.post(webhook_url, json=data)
if response.status_code == 204:
print("Log: Message sent successfully.")
elif response.status_code == 429:
retry_after = response.json().get("retry_after", 1) / 1000.0
print(f"Rate limit hit. Retrying after {retry_after} seconds...")
time.sleep(retry_after)
continue
else:
print(f"Failed to send message, status code: {response.status_code}")
time.sleep(interval) # Use a safer interval
except KeyboardInterrupt:
print("Program stopped by user.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
main()