Discord.JS获取附件URL并在通道中发送



我有这个机器人程序代码"discord.js v13";,我需要获得附加文件的URL并立即发送链接。我该怎么做?我将把代码部分留在下面

// save file in folder 'musicas'
stream.pipe(createWriteStream(__dirname + `/musicas/${pegaid}.mp3`)).on('finish', () => {
// Sending the attachment, and its link
try {
message.channel.send({
files: [{
attachment: (__dirname + `/musicas/${musicid}.mp3`),
name: `${musicid}.mp3`
}],
});
} catch (e) {
return message.channel.send(`${message.author}, Error ao tentar converter a música!`);
}

我猜您想要发送附加文件的URL。不幸的是,您只能在先发送附件后才能发送URL。

const image = await message.channel.send({ files: [{ attachment: `full-path`, name: `something.mp3` }] });
return message.channel.send({ content: `${image.attachments.first().proxyURL}` });

点击此处,在discord.js文档中了解更多信息。

最新更新