Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a Discord message to a channel using JS & Chrome Console?

How to send a Discord message to a discord channel using JS & Chrome Console without using Discord API?

It seems that it is impossible...

like image 563
nahha Avatar asked Dec 24 '17 22:12

nahha


People also ask

How do I send a message to Discord using API?

Under Method, select POST. Under Body Type, select Raw. Under Content Type, select JSON (application/json) Finally, under Request Content, type in the message to be sent to the channel as a JSON payload as per Discord's API.

Is JavaScript good for Discord bot?

discord.js is a powerful Node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.


2 Answers

Open discord console : ctrl + shift + i (doesn't work? see edit below)

Then go into the network tab.

Now we need to sniff a message, so type a message in discord and send it.

Then in the console network tab right click the request named "messages", and pick "Copy as fetch".

Then go to the "Console" tab. Paste the request.

Edit this request to remove the "noonce" field.

And also there, edit the "content" field with your message.

When you press enter it should send it.

EDIT

As of today, discord team disabled the console by default.

There are 2 options to use it :

  • either open discord in your web browser and use F12 to open the console
  • or set "DANGEROUS_ENABLE_DEVTOOLS_ONLY_ENABLE_IF_YOU_KNOW_WHAT_YOURE_DOING": to true in %appdata%/discord/settings.json
like image 144
Loïc Avatar answered Sep 29 '22 12:09

Loïc


I know this is an old question, but I think I found the answer you were looking for. Many of the headers that you may have thought to use are unnecessary for this to work.

The headers that matter for most everything:

authorization: TOKEN

accept: "/"

authority: discordapp.com

When sending a message, you must also specify the content-type:

content-type: application/json

Therefore, you can easily construct a JavaScript POST request to send a discord message to a channel using the following code or similar:

messsage = "Hi!";

token = "TOKEN";

channel_id = "CHANNEL ID";

channel_url = `https://discordapp.com/api/v6/channels/${channel_id}/messages`

request = new XMLHttpRequest();
request.withCredentials = true;
request.open("POST", channel_url);
request.setRequestHeader("authorization", token);
request.setRequestHeader("accept", "/");
request.setRequestHeader("authority", "discordapp.com");
request.setRequestHeader("content-type", "application/json");
request.send(JSON.stringify({ content: message }));
like image 40
Tobyhn Avatar answered Sep 29 '22 12:09

Tobyhn