Created
June 15, 2021 11:03
-
-
Save gotjoshua/b160004a8982780ec821158dd0ad7c70 to your computer and use it in GitHub Desktop.
moralis sendToDiscord channel hook
This file contains 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
const sendToDiscord = async (channelHookURL, content) => { | |
// https://discord.com/developers/docs/resources/webhook#execute-webhook | |
let httpResponse; let status = 'success' | |
try { | |
httpResponse = await Moralis.Cloud.httpRequest({ | |
method: 'POST', | |
url: channelHookURL, | |
body: { | |
flags: 1 << 2, // not working attempt to prevent links from embedding | |
content, | |
}, | |
}) | |
} catch (error) { | |
status = 'error' | |
log(JSON.stringify(error.data, null, 2), 'discord caught :') | |
} | |
log(`discord ${status}`) | |
// logger.info(JSON.stringify(httpResponse)) | |
return { httpResponse, status } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment