Using Puppeteer to send messages on Discord without the use of a bot or application

Currently, I am coding a Puppeteer script to automate actions on Discord Web. Specifically, I need the script to open Discord Web, log in (including manual captcha and authorization steps), navigate to a channel, enter a message into the chat input field, and send it successfully.

This project stands out from others because it does not involve using a Discord Webhook or Application for message delivery.

The main challenge I am facing is that the element where the message is entered is a contenteditable div.

One potential issue could be that even though simulating the Enter key press appears to work visually, the message may not be sent because setting the innerText of the div does not effectively communicate the intended message to be sent. I have also observed that the placeholder text remains visible.

For reference, please see the screenshot illustrating the specific element: https://i.sstatic.net/YEk4H.png

The code segment responsible for sending the message looks like this:

const selector = 'div[contenteditable=true]:nth-child(2)';
page.goto('https://discord.com/channels/2358929835296835/39057203957203');
await page.waitForSelector(selector);
await page.focus(selector);
await page.$eval(selector, el => el.innerText = 'Hello, world!');
await page.keyboard.press((String.fromCharCode(13) as any));

I would greatly appreciate any suggestions you may have regarding alternative methods to successfully send the message. The current code successfully populates the message form with 'Hello, world' but encounters difficulties in sending it.

UPDATE: It seems that Discord employs a library called Slate for their messaging feature which constructs a nested span tree as messages are typed. While I have managed to edit the relevant span with text, I still face challenges triggering the message to be sent.

I have also reached out to the creator with the same inquiry, however, no solutions have been found yet.

Answer №1

Recalling a similar experience, I believe the text can be found within a deeply nested span element beneath the referenced DIV. It's worth noting that modifying innerText may not always work reliably, so consider clicking and typing instead.

const selector = '#app-mount > div.app-1q1i1E > div > div.layers-3iHuyZ.layers-3q14ss > div > div > div > div.content-98HsJk > div.chat-3bRxxu > div.content-yTz4x3 > main > form > div:nth-child(1) > div > div > div.scrollableContainer-2NUZem.webkit-HjD9Er > div > div.textArea-12jD-V.textAreaSlate-1ZzRVj.slateContainer-3Qkn2x > div.markup-2BOw-j.slateTextArea-1Mkdgw.fontSize16Padding-3Wk7zP'
page.goto('https://discord.com/channels/2358929835296835/39057203957203')
await page.waitForSelector(selector, {timeout: 0})
var text = await page.$(selector)
await text.click()
await text.type("hello world")
await page.keyboard.press("Enter")

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular log out function to automatically close pop-up windows

Within my application, there is a page where users can open a popup window. When the user clicks on logout, it should close the popup window. To achieve this, I have used a static variable to store the popup window reference in the Global.ts class. public ...

Update the page when the Cancel prompt is selected

Issue: I am facing a problem with my web page. After entering data and clicking save, a confirmation pop-up appears. If I choose to cancel, I want the page to refresh so that the entered data is cleared. Below is the current code for the confirmation pro ...

The functionality of jquery.load() seems to be experiencing issues in Internet Explorer when attempting to load an HTML file

Code $('.form').load('http://'+window.location.hostname+':8423/html/form/form_generate.html/?session='+session); In an attempt to load a html file from a different port on the same server. The original server is accessible ...

Experiencing difficulties when trying to upload images using multer in an Express application with Node.js

I have been using multer to successfully upload images into a folder within my project. Despite not encountering any errors while using multer, I am facing an issue where the upload is not functioning as expected in my project, although it works perfectly ...

Combining union types with intersection operators in Typescript

Here's a concept for an event handling system: type EventMap = Record<string, any>; type EventKey<T extends EventMap> = string & keyof T; type EventReceiver<T> = (params: T) => void; interface Emitter<T extends EventMap&g ...

Updating an AngularJS nested template dynamically during execution

Currently, I am facing an issue where I have a template nested within another template, and I want to load it dynamically when a specific button is clicked. Here is what I have attempted so far: This is the main body.html (which loads when a URL is provid ...

Is it possible to direct the user to a particular link upon swiping to unlock?

Hello everyone, I could use some assistance with this code. I am looking to redirect someone to a specific page when they swipe to unlock and automatically transfer them to another page when the swipe ends. Any help is greatly appreciated. Thank you! $ ...

Create dynamic elements in Vue.js components based on an object

I'm currently working on a component that will display elements within VueJs virtual dom using Vuex state. However, I have encountered an error that I am unable to comprehend and resolve: Avoid using observed data object as vnode data: {"class":"b ...

Functionality of the copy button

I have a Bootstrap code snippet that I want to use to create an address and add copy button functionality: <div class="modal fade" id="bitcoinModal" role="dialog"> <div class="modal-dialog modal-lg"> & ...

Improving performance in Next.JS by optimizing unused JavaScript resources

Currently working on my first website using Next.js and experiencing poor performance scores after running a lighthouse test. The issue seems to be related to unused JavaScript files located in the chunk folder. I've come across suggestions to split t ...

Guide on how to select a specific button from a set of buttons in JQuery without using a class name or id

Is it possible to select a specific button from a group of buttons using jQuery without utilizing a class or id? For example: <body> <button>Click Me</button> <button>Click Me</button> <button class="food"& ...

What could be the reason for the malfunction of the Bootstrap panel toggle feature in a ReactJS production build

In my ReactJS development, I have successfully added Bootstrap panel toggle functionality. However, I encountered an issue when deploying the React build code - the panel is not expanding. After investigating, I realized that the problem lies in using hr ...

Keep track of numerous clicks and gather all values in a single line

I have a scenario where I need to fetch values from multiple buttons on my webpage and display them together in one line. How can this be achieved? There are 3 buttons, each returning a specific value when clicked: Dark : scoop Danger : swoosh Warning ...

Manage errors in Node.js and display the error message on an HTML page

My function logs errors, but I want to display the same data in an HTML <div> if an error occurs. The <div> should only appear when there is an error and show the error message to the user. app.js console.log('Pulling Image from DockerHu ...

After a postback triggered by a different update panel, the item that was initially added to the dropdown menu using

Why do I encounter an issue with two update panels both set to conditional mode? In the first update panel, I have two dropdowns where selecting an item in the first dropdown triggers the addition of an item in the second dropdown via JavaScript. The sec ...

Optimizing AngularJS performance with REST service caching

My AngularJS application requires caching of REST service responses, and I've come across libraries like angular-cached-resource that store data in the local browser storage. However, there are times when certain cached responses need to be deleted d ...

Tips for implementing an HTML modal with AngularJS binding for a pop up effect

As a beginner in AngularJS, I am facing a challenge. I have an HTML page that I want to display as a pop-up in another HTML page (both pages have content loaded from controllers). Using the router works fine for moving between pages, but now I want the s ...

Adhere" external documents onto a grid with the help of three.js

Currently, I am working in a .Stl editor on Three.js and I am facing the challenge of aligning my imported .Stl files to the grid properly. The issue is that they are ending up either partially above or below the grid, instead of sticking right onto it. I ...

Firebase Angular encountering issues with AngularFirestoreModule

I have encountered a challenge with Firebase authentication in my Angular applications. Due to updated read and write rules that require auth!=null, I successfully implemented Firebase authentication in one of my apps using Angular 13. Now, I am trying to ...

Retrieve every item in a JSON file based on a specific key and combine them into a fresh array

I have a JSON file containing contact information which I am retrieving using a service and the following function. My goal is to create a new array called 'contactList' that combines first names and last names from the contacts, adding an &apos ...