为 discord.js 中的文件发送缓冲区
Send buffer for file in discord.js
我知道您可以从文件名发送,但我无法访问文件系统,因为我使用的是 Heroku。
client.sendFile(messagedata, writer.toBuffer(), "file.png", "Just a message");
问题在于
TypeError: client.sendFile is not a function
discord.js 中的哪个等效函数允许我将缓冲区作为文件发送?
.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);
我知道它很旧,但这里有一个文本示例,用于在不使用文件系统的情况下在通道中发送文件。
const { MessageAttachment } = require('discord.js')
const buffer = Buffer.from('Text in file')
const attachment = new MessageAttachment(buffer, 'file.txt')
channel.send(attachment)
我知道您可以从文件名发送,但我无法访问文件系统,因为我使用的是 Heroku。
client.sendFile(messagedata, writer.toBuffer(), "file.png", "Just a message");
问题在于
TypeError: client.sendFile is not a function
discord.js 中的哪个等效函数允许我将缓冲区作为文件发送?
.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);
我知道它很旧,但这里有一个文本示例,用于在不使用文件系统的情况下在通道中发送文件。
const { MessageAttachment } = require('discord.js')
const buffer = Buffer.from('Text in file')
const attachment = new MessageAttachment(buffer, 'file.txt')
channel.send(attachment)