|
| 1 | +# Discord Webhook Testing Scripts |
| 2 | + |
| 3 | +This directory contains scripts to test Discord webhook notifications without running a Minecraft server. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +### Bash Script (`test-discord-webhook.sh`) |
| 8 | +- Bash shell |
| 9 | +- Java installed (any version with `javac` and `java` commands) |
| 10 | + |
| 11 | +### Python Script (`test-discord-webhook.py`) |
| 12 | +- Python 3.x installed |
| 13 | + |
| 14 | +## Getting a Discord Webhook URL |
| 15 | + |
| 16 | +1. Go to your Discord server settings |
| 17 | +2. Navigate to **Integrations** → **Webhooks** |
| 18 | +3. Click **New Webhook** |
| 19 | +4. Configure the webhook: |
| 20 | + - Set a name (e.g., "Herald Bot") |
| 21 | + - Choose the channel where notifications should be sent |
| 22 | + - Copy the webhook URL |
| 23 | +5. Keep this URL secure - don't share it publicly! |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +### Bash Script |
| 28 | + |
| 29 | +```bash |
| 30 | +# Basic usage (uses default player and server names) |
| 31 | +./test-discord-webhook.sh https://discord.com/api/webhooks/123456/abcdef |
| 32 | + |
| 33 | +# With custom player name |
| 34 | +./test-discord-webhook.sh https://discord.com/api/webhooks/123456/abcdef Steve |
| 35 | + |
| 36 | +# With custom player and server names |
| 37 | +./test-discord-webhook.sh https://discord.com/api/webhooks/123456/abcdef Steve "My Awesome Server" |
| 38 | +``` |
| 39 | + |
| 40 | +### Python Script |
| 41 | + |
| 42 | +```bash |
| 43 | +# Basic usage (uses default player and server names) |
| 44 | +python3 test-discord-webhook.py https://discord.com/api/webhooks/123456/abcdef |
| 45 | + |
| 46 | +# With custom player name |
| 47 | +python3 test-discord-webhook.py https://discord.com/api/webhooks/123456/abcdef Steve |
| 48 | + |
| 49 | +# With custom player and server names |
| 50 | +python3 test-discord-webhook.py https://discord.com/api/webhooks/123456/abcdef Steve "My Awesome Server" |
| 51 | +``` |
| 52 | + |
| 53 | +## What the Scripts Do |
| 54 | + |
| 55 | +These scripts simulate the Herald plugin's Discord notification by: |
| 56 | + |
| 57 | +1. Taking a Discord webhook URL as input |
| 58 | +2. Formatting a message in the same way the plugin does: `**PlayerName** joined the **ServerName** server` |
| 59 | +3. Sending the message to Discord via HTTP POST request |
| 60 | +4. Reporting success or failure |
| 61 | + |
| 62 | +The message will appear in your Discord channel exactly as it would when a player joins your Minecraft server. |
| 63 | + |
| 64 | +## Example Output |
| 65 | + |
| 66 | +### Successful Test |
| 67 | +``` |
| 68 | +======================================== |
| 69 | +Discord Webhook Test Script |
| 70 | +======================================== |
| 71 | +
|
| 72 | +Testing Discord webhook... |
| 73 | +Webhook URL: https://discord.com/api/webhooks/123456/**** |
| 74 | +Player Name: Steve |
| 75 | +Server Name: My Awesome Server |
| 76 | +
|
| 77 | +Sending test message... |
| 78 | +
|
| 79 | +Sending payload: {"content": "**Steve** joined the **My Awesome Server** server"} |
| 80 | +Response code: 204 |
| 81 | +✓ SUCCESS: Message sent to Discord! |
| 82 | +Check your Discord channel for the notification. |
| 83 | +
|
| 84 | +======================================== |
| 85 | +Test completed successfully! |
| 86 | +======================================== |
| 87 | +``` |
| 88 | + |
| 89 | +### Failed Test |
| 90 | +``` |
| 91 | +======================================== |
| 92 | +Discord Webhook Test Script |
| 93 | +======================================== |
| 94 | +
|
| 95 | +Testing Discord webhook... |
| 96 | +Webhook URL: https://discord.com/api/webhooks/invalid/**** |
| 97 | +Player Name: Steve |
| 98 | +Server Name: Minecraft |
| 99 | +
|
| 100 | +Sending test message... |
| 101 | +
|
| 102 | +✗ ERROR: Failed to send message to Discord |
| 103 | +Error: Discord webhook returned error code: 404 |
| 104 | +
|
| 105 | +======================================== |
| 106 | +Test failed! |
| 107 | +======================================== |
| 108 | +``` |
| 109 | + |
| 110 | +## Troubleshooting |
| 111 | + |
| 112 | +### "Command not found" Error |
| 113 | +- **Bash script**: Make sure the script is executable: `chmod +x test-discord-webhook.sh` |
| 114 | +- **Python script**: Make sure the script is executable: `chmod +x test-discord-webhook.py` |
| 115 | +- **Java not found**: Install Java Development Kit (JDK) |
| 116 | +- **Python not found**: Install Python 3 |
| 117 | + |
| 118 | +### "Error code: 404" or "Error code: 401" |
| 119 | +- Your webhook URL is invalid or has been deleted |
| 120 | +- Create a new webhook and try again |
| 121 | + |
| 122 | +### "Error code: 429" |
| 123 | +- You're being rate-limited by Discord |
| 124 | +- Wait a few seconds and try again |
| 125 | + |
| 126 | +### No Message Appears in Discord |
| 127 | +- Check that you're looking at the correct channel |
| 128 | +- Verify the webhook is configured for the right channel |
| 129 | +- Make sure the webhook hasn't been deleted |
| 130 | + |
| 131 | +## Security Note |
| 132 | + |
| 133 | +**Never commit your actual webhook URL to version control!** These scripts mask the webhook token in output for security, but you should still keep your webhook URLs private. |
| 134 | + |
| 135 | +## Integration with Herald Plugin |
| 136 | + |
| 137 | +Once you've verified your webhook URL works with these scripts, you can configure it in your Herald plugin's `config.yml`: |
| 138 | + |
| 139 | +```yaml |
| 140 | +discord: |
| 141 | + enabled: true |
| 142 | + webhook-url: "https://discord.com/api/webhooks/123456/abcdef" |
| 143 | +``` |
| 144 | +
|
| 145 | +The plugin will send notifications in exactly the same format as these test scripts. |
0 commit comments