user3498001
user3498001

Reputation:

Connecting Heroku Webhooks with Discord

I am trying to have updates to my heroku app sent to a Discord channel via webhook. However, the delivery attempts fail. I've double checked the Payload URL and it is correct. Not sure how to proceed from here.

Upvotes: 5

Views: 3742

Answers (3)

JoshieGemFinder
JoshieGemFinder

Reputation: 21

Found this JS code, should work (change params variable and where it says webhook to your webhook url)

let x = new XMLHttpRequest();
x.open("POST", `<webhook link>`);
x.setRequestHeader('Content-type', 'application/json');
let params = {
    username: "Webhook Bot",
    content: "<message content as a string>"
}
x.send(JSON.stringify(params));

i should mention that to mention a channel instead of #channel-name you'll have to use <#channelid>, for example <#1234567890> instead of #foo-bar

(this is my first post, sorry if it's a bit bad)

Upvotes: 2

Shandon Anderson
Shandon Anderson

Reputation: 21

Without being able to see your code and the request structure you are using it will be hard to determine where the issue is coming from exactly, but one thing you might what to check is how you are sending the JSON payload to the Discord webhook URL.

Discord does not seem to accept the request unless you specify that the body of the payload is JSON. I discovered this because of an application I am working on currently. I know this answer is coming significantly after the fact, but it might help someone else down the line!

Upvotes: 1

Lamp
Lamp

Reputation: 655

Heroku's webhook format is not compatible with Discord so you can't just put a Discord webhook URL into Heroku. You need a middle-man server to receive events from Heroku, and construct and send corresponding messages to Discord.

Upvotes: 2

Related Questions