Created
June 1, 2023 06:40
-
-
Save dorktoast/5ceb0f1a0504ce8a76b9e64f71ab9129 to your computer and use it in GitHub Desktop.
Send a Discord message via Apps Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function PostDiscordMessage(message) { | |
| // Target Data | |
| var discordUrl = 'https://discord.com/api/webhooks/YOUR_WEBHOOK_URL'; | |
| // replace pings with appropriate IDs | |
| message = message.ToString().replace("@SomeRole","<@&976180323052294245>"); | |
| var payload = JSON.stringify({content: message}); | |
| var params = { | |
| headers: { | |
| 'Content-Type': 'application/json' | |
| }, | |
| method: "POST", | |
| payload: payload, | |
| muteHttpExceptions: true | |
| }; | |
| var response = UrlFetchApp.fetch(discordUrl, params); | |
| Logger.log(response.getContentText()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment