Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
Cómo usar discord.js en HTML

Estoy tratando de crear un tablero discord.js, pero en realidad no puedo usar la biblioteca discord.js y conectarla con el cliente

Aquí está mi código javascript (El proyecto es node.js usando express para enviar un archivo HTML)

 const express = require('express'); const bodyparser = require('body-parser') const app = express(); const path = require('path'); app.get('/', (req, res) => { res.sendFile(path.join(__dirname + '/home.html')) }); app.use(bodyparser.text()) app.listen(3000, () => { console.log('server started'); });

Y mi código HTML

 <!DOCTYPE html> <html> <head> <style> @import url('https://fonts.googleapis.com/css2?family=Prompt:ital,wght@1,200&display=swap'); #title { font-family: 'Prompt', sans-serif; text-align: center; } </style> </head> <body> <h1 id="title">Bot Dashboard</h1> <p id="join">Join our discord!</p> <iframe src="Removed Widget URL" width="350" height="200" allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe> <button id="sendtest" onclick="">Send a test</button> </body> </html>

Quiero que el botón de prueba envíe un mensaje en un canal (Todo lo que necesito es una función que pueda ejecutarse en node.js). ¿Qué estaría en el "onclick"?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si su servidor Express puede acceder a su objeto de cliente discord.js, puede enviar una solicitud HTTP desde el navegador a Express, que puede devolver la información de su bot.

En su archivo HTML:

 <!DOCTYPE html> <html> <head> <style> @import url('https://fonts.googleapis.com/css2?family=Prompt:ital,wght@1,200&display=swap'); #title { font-family: 'Prompt', sans-serif; text-align: center; } </style> <script> const buttonText = document.getElementById("buttontext"); function botTest() { fetch("https://localhost:3000/test") .then(() => response.json()) .then((data) => buttonText.innerText = `The bot's tag is ${data.tag}`); } </script> </head> <body> <h1 id="title">Bot Dashboard</h1> <p id="join">Join our discord!</p> <iframe src="Removed Widget URL" width="350" height="200" allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe> <button onclick="botTest()">Send a test</button> <p id="buttontext">Click the button!</p> </body> </html>

En su archivo Express:

 const express = require('express'); const bodyparser = require('body-parser') const app = express(); const path = require('path'); app.get('/', (req, res) => { res.sendFile(path.join(__dirname + '/home.html')) }); app.get('/test', (req, res) => { // make sure your discord.js client is available somewhere in this file res.json({ tag: client.user.tag }); }); app.use(bodyparser.text()) app.listen(3000, () => { console.log('server started'); });

Asegúrese de que su cliente discord.js esté disponible en algún lugar de su archivo. Esto puede ser una importación desde su archivo index.js, o cualquier archivo que tenga su instancia de Cliente y lo exporte usando module.exports .

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!