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

743
Views
Cómo adjuntar una imagen a la respuesta del comando de barra discord.js v13

Estoy creando un bot que tiene comandos de barra y quiero adjuntar un archivo, sin mensaje, solo un archivo de imagen. Intenté hacer esto, pero termina dándome un mensaje de error vacío.

 const attachment = new MessageAttachment("image.bmp"); client.api.interactions(interaction.id, interaction.token).callback.post({ data: { type: 4, data: { files: [attachment] } } })

Entonces, mi pregunta es, ¿cómo adjunto una imagen con esta interacción de discordia en formato JSON?

ACTUALIZACIÓN: actualmente tengo esto, que todavía no funciona, pero me da esto .

 const file = new MessageAttachment ( "image.bmp" ); client.api.interactions(interaction.id, interaction.token).callback.post({ data: { type: 4, data: { content: "hello", "embeds": [ { "title": `This is a cool embed`, image: { url: 'attachment://image.bmp', }, "type": "rich", "description": "", "color": 0x00FFFF } ] }, } })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Con Discord.js V13, use una combinación de await interaction.deferReply(); para permitir que el comando funcione más tiempo, entonces puede usar await interaction.editRepy({ files: [attatchment] }); para actualizar deferReply(); con su archivo adjunto. Un ejemplo de comando de barra inclinada se vería así en un controlador de comando de barra inclinada:

 const { SlashCommandBuilder } = require('@discordjs/builders'); const { MessageAttachment } = require('discord.js') module.exports = { data: new SlashCommandBuilder() .setName('attachment') .setDescription('Upload a file') .addAttachmentOption(option => option.setName('attachment').setDescription('Upload an attachment')), async execute(interaction) { let attachment = await interaction.options.getAttachment('attachment'); await interaction.deferReply(); // Deffer Reply so we have more time console.log(attachment.url) // You can see URL, which is what we will use later console.log(attachment.contentType) // See the file type attachment = await new MessageAttachment(attachment.url, 'image.png'); // Converting URL to image as well as naming the file/assigning the file type await interaction.editReply( // Sending the image { files: [attachment] } ) }, };

¡Espero que esto ayude! :D

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!