How to send message to specific discord channel from your server application?

How to send message to specific discord’s channel from your server application?

Had you wonder how to send the log / messages from the server application to discord channel? In my personal poject I use NodeJs for the server side, each of the…


This content originally appeared on DEV Community and was authored by John Melody Me

How to send message to specific discord's channel from your server application?

Had you wonder how to send the log / messages from the server application to discord channel? In my personal poject I use NodeJs for the server side, each of the important details from the server will be sent to my discord's channel. For instance, each time my user made a payment or register for my app. I am about to demonstrate how exactly I did it.

I use the ES6 dicipline for my application.

Packages I will be using are axios, and nodemon.

  1. Initiate a project by npm init -y.
  2. get the webhok url by going to your channel's settings -> integration -> create webhook.
  3. start coding.

In this case I will use the method of HTTP POST request to the webhook.
As in bash you can simply do :

#!/bin/sh
url = "thewebhookurl"

curl -H "Content-Type: application/json" -X POST -d '{"content":"'"YOUR WHAT EVER MESSAGE "'"}' $url

but in nodejs,


 log(msg) {
        let webhook_url = 'thewebhoooklink';

        let params = {
            username: 'ABC',
            content: msg,
        };

        return axios({
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            data: JSON.stringify(params),
            url: webhook_url,
        });
    }

and it should work but calling the function log('something something');

HAPPY CODING!


This content originally appeared on DEV Community and was authored by John Melody Me


Print Share Comment Cite Upload Translate Updates
APA

John Melody Me | Sciencx (2021-10-01T02:07:34+00:00) How to send message to specific discord channel from your server application?. Retrieved from https://www.scien.cx/2021/10/01/how-to-send-message-to-specific-discord-channel-from-your-server-application/

MLA
" » How to send message to specific discord channel from your server application?." John Melody Me | Sciencx - Friday October 1, 2021, https://www.scien.cx/2021/10/01/how-to-send-message-to-specific-discord-channel-from-your-server-application/
HARVARD
John Melody Me | Sciencx Friday October 1, 2021 » How to send message to specific discord channel from your server application?., viewed ,<https://www.scien.cx/2021/10/01/how-to-send-message-to-specific-discord-channel-from-your-server-application/>
VANCOUVER
John Melody Me | Sciencx - » How to send message to specific discord channel from your server application?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/01/how-to-send-message-to-specific-discord-channel-from-your-server-application/
CHICAGO
" » How to send message to specific discord channel from your server application?." John Melody Me | Sciencx - Accessed . https://www.scien.cx/2021/10/01/how-to-send-message-to-specific-discord-channel-from-your-server-application/
IEEE
" » How to send message to specific discord channel from your server application?." John Melody Me | Sciencx [Online]. Available: https://www.scien.cx/2021/10/01/how-to-send-message-to-specific-discord-channel-from-your-server-application/. [Accessed: ]
rf:citation
» How to send message to specific discord channel from your server application? | John Melody Me | Sciencx | https://www.scien.cx/2021/10/01/how-to-send-message-to-specific-discord-channel-from-your-server-application/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.