Skip to content

Instantly share code, notes, and snippets.

Last active August 19, 2023 14:52
  • Star 41 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
js post request example for discord webhooks using the fetch web api
// node.js versions pre-v0.18.0 do not support the fetch api and require a polyfill
// const fetch = require('node-fetch');
method: 'post',
headers: {
'Content-Type': 'application/json',
body: JSON.stringify({
// the username to be displayed
username: 'webhook',
// the avatar to be displayed
// contents of the message to be sent
'user mention: <@279098137484722176>, role mention: <@&496160161459863552>, channel mention: <#508500699458306049>',
// enable mentioning of individual users or roles, but not @everyone/@here
allowed_mentions: {
parse: ['users', 'roles'],
// embeds to be sent
embeds: [
// decimal number colour of the side of the embed
color: 11730954,
// author
// - icon next to text at top (text is a link)
author: {
name: 'dragonwocky',
url: '',
icon_url: '',
// embed title
// - link on 2nd row
title: 'title',
// thumbnail
// - small image in top right corner.
thumbnail: {
// embed description
// - text on 3rd row
description: 'description',
// custom embed fields: bold title/name, normal content/value below title
// - located below description, above image.
fields: [
name: 'field 1',
value: 'value',
name: 'field 2',
value: 'other value',
// image
// - picture below description(and fields)
image: {
// footer
// - icon next to text at bottom
footer: {
text: 'footer',
Copy link

dragonwocky commented Aug 30, 2022

@BizarreMaster16 that line is only required if you are using Node.js pre-v18.0.0 and is a limitation of old Node.js versions. This webhook code can be run in any other JavaScript environment (e.g. browser, Deno, Bun) without the need for a polyfill, so that line is up to users to add themselves if they need it instead of being part of the general code example, but I've added a comment to the gist to explain that.

Copy link

@dragonwocky OK thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment