Advertisement
Python253

discord_webhook

Jun 22nd, 2024 (edited)
756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: discord_webhook.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    - This script demonstrates how to send a message to a Discord webhook using Python's requests module.
  10.  
  11. Requirements:
  12.    - Python 3.x
  13.    - requests module
  14.        
  15. Usage:
  16.    - Replace 'https://discord.com/api/webhooks/...' with your actual Discord webhook URL.
  17.    - Run the script to send a test message to your Discord channel.
  18.    
  19. Additional Notes:
  20.    - Discord webhooks allow external services to send messages to Discord channels.
  21.    - Ensure your webhook URL is correct and formatted properly.
  22. """
  23.  
  24. import requests
  25.  
  26. # Your webhook URL
  27. webhook_url = 'https://discord.com/api/webhooks/...'
  28.  
  29. print(f"Sending To: {webhook_url}\nClick the link above to see the full webhook object.")
  30.  
  31. # Message content
  32. message = {
  33.     "content": "Hello,\nThis is a test message from my webhook!\n...\nTest complete!"
  34. }
  35.  
  36. # Send the message
  37. response = requests.post(webhook_url, json=message)
  38.  
  39. # Check the response status
  40. if response.status_code == 204:
  41.     print('\nMessage sent successfully!')
  42. else:
  43.     print('Failed to send message', response.status_code)
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement