DEV Community

Discussion on: Send automated Discord messages through Webhooks using JavaScript

Collapse
 
oskarcodes profile image
Oskar Codes

Set the content field to the value of your input:

content: document.querySelector("input").value // could be "textarea" as well
Enter fullscreen mode Exit fullscreen mode
Collapse
 
konrad_szacha_96d4d2fe379 profile image
Konrad Szacha

i did it like that but this is dont working please help me bro
<br> function sendMessage() {<br> const request = new XMLHttpRequest();<br> request.open(&quot;POST&quot;, &quot;<a href="https://discord.com/api/webhooks/921856294481186857/cJd-f85MqKVdLyFotaxZf7yzWH-ILK3VGPL1H7W2IX7UsQwIs0yDEap7cG4oF18uE4K0%22" rel="nofollow">https://discord.com/api/webhooks/921856294481186857/cJd-f85MqKVdLyFotaxZf7yzWH-ILK3VGPL1H7W2IX7UsQwIs0yDEap7cG4oF18uE4K0&quot;</a>);</p> <div class="highlight"><pre class="highlight plaintext"><code> request.setRequestHeader('Content-type', 'application/json'); const params = { username: "My Webhook Name", avatar_url: "", content: document.querySelector("input").value } request.send(JSON.stringify(params)); } </code></pre></div> <p>


and how i should modify this

Thread Thread
 
oskarcodes profile image
Oskar Codes

Where did you copy that code from? That’s some plain HTML displaying JavaScript code, not executing it.