在 discord.js 中发送文件缓冲区
Posted
技术标签:
【中文标题】在 discord.js 中发送文件缓冲区【英文标题】:Send buffer for file in discord.js 【发布时间】:2018-09-20 17:18:39 【问题描述】:我知道您可以从文件名发送,但我无法访问文件系统,因为我使用的是 Heroku。
client.sendFile(messagedata, writer.toBuffer(), "file.png", "Just a message");
问题是
TypeError: client.sendFile is not a function
discord.js 中的什么等效函数可以让我将缓冲区作为文件发送?
【问题讨论】:
【参考方案1】:.sendFile()
已弃用。现在只有.send()
要将文件发送给用户:
message.author.send(
files: [
attachment: 'entire/path/to/file.jpg',
name: 'file.jpg'
]
)
.then(console.log)
.catch(console.error);
要将文件发送到消息通道,您可以这样做:
message.channel.send(
files: [
attachment: 'entire/path/to/file.jpg',
name: 'file.jpg'
]
)
.then(console.log)
.catch(console.error);
【讨论】:
【参考方案2】:我知道它很旧,但这里有一个文本示例,在不使用文件系统的情况下在通道中发送文件。
const MessageAttachment = require('discord.js')
const buffer = Buffer.from('Text in file')
const attachment = new MessageAttachment(buffer, 'file.txt')
channel.send(attachment)
【讨论】:
以上是关于在 discord.js 中发送文件缓冲区的主要内容,如果未能解决你的问题,请参考以下文章