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 } ] }, } })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