Forward SMS Message to Discord Using Twilio

Step 1: Create a Discord Channel

Start by click on this icon on your Discord app.

Create Discord Server Button

Go through the steps and name your server.

Next, find a channel you would like to send messages to. Click on this icon to "Edit Channel".

Text Channel Settings

In "Integrations", create a webhook.

Create a Webhook Bot

Name the bot, hit save, and save the webhook URL for later.

Save Webhook URL

Step 2: Twilio Setup

Create an account or sign into Twilio, and deploy this application.

Once deployed, click "Go to live application", and click the "Edit this application" button.

Under Settings -> Environment Variables, add a new key named DISCORD_WEBHOOK_URL and paste in your webhook.

Add Discord Webhook URL as Environment Variable

Under Settings -> Dependencies, add module got 11.8.3 (Be sure to use this version!)

Add dependency to node environment

Go to Functions and select your function file.

Add Discord Webhook URL as Environment Variable

Delete the boilerplate code and add the follow snippet:

// Make sure the function is async!
exports.handler = async function (context, event, callback) {
    const twiml = new Twilio.twiml.MessagingResponse();
    const { default: got } = await import('got');
    const url = context.DISCORD_WEBHOOK_URL;

    const options = {
        json: {
        username: "Your Bot Name",
        avatar_url: "",
        content: `${event.Body}`
        }
    }

    got.post(url, options)
        .then(function(response) {
        console.log(response.body)
    });
};

Now, click Save and then Deploy All.

Add Code Snippet to Function

Step 3: Deploy and Test

Try sending a text message to your Twilio phone number and you should receive the text in your Discord channel.

And there you go, you have successfully forwarded SMS messages to a Discord channel!