I need to alter this html so it sends a random response to a webhook instead of just a static reply

Viewed 26

So this is the code I have so far I am just trying to get it to submit a random message to the webhook instead of just a static message! I'm pretty sure I need to set up an array or something please help!

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>random title</title>


    <button onclick="sendMessage()">Send</button>


  <script>
    function sendMessage() {
      const request = new XMLHttpRequest();
      request.open("POST", "/mywebhook address");

      request.setRequestHeader('Content-type', 'application/json');

      const params = {
        username: "My Webhook Name",
        avatar_url: "",
        content: "THIS IS THE SECTION I WANT TO BE A RANDOM NUMBER!!!"
      }

      request.send(JSON.stringify(params));
    }
 </script>
1 Answers

Editing the context of the <script> only:

<script>
    function sendMessage() {
      const request = new XMLHttpRequest();
      request.open("POST", "/mywebhook address");

      request.setRequestHeader('Content-type', 'application/json');

      const params = {
        username: "My Webhook Name",
        avatar_url: "",
        content: Math.floor(Math.random() * 100) + 1 //returns a random number 0-100
      }

      request.send(JSON.stringify(params));
    }
 </script>
Related