我正在Discord.js中编写一个“移动消息”机器人,但是由于某些原因,我无法将图像从原始消息发送到新频道。
代码如下:
exports.run = async (client, message, args) => {
if(!message.member.hasPermission('MANAGE_MESSAGES'))
return message.channel.send(':no_entry: You must have permissions to manage messages in order to use this command')
const channel = message.guild.channels.get(client.utils.parseMention(args[0]))
if(!channel || channel.type !== 'text')
return message.channel.send(`:x: I cound not find a text channel based on ${client.utils.escapeMarkdown(args[0])}`)
if(!channel.permissionsFor(message.guild.me).has('MANAGE_WEBHOOKS'))
return message.channel.send(`:no_entry: I don't have permissions to create webhooks in ${channel}`)
const msg = args[1]
if(!msg)
return message.channel.send('Please specify the ID of the message you want to move')
message.channel.fetchMessage(msg).then(async (m) => {
const wh = await channel.createWebhook('Message moving', client.user.displayAvatarURL, `Message move by ${message.author.tag}`)
await wh.send(m.content || '', { disableEveryone: true, username: m.author.username, avatarURL: m.author.displayAvatarURL, embeds: m.embeds, files: m.attachments.array() })
await wh.delete('Finished')
await m.delete()
message.channel.send('The message has been moved')
}).catch((e) => {
if(e.code === 50035)
return message.channel.send('Not a valid message ID')
if(e.code === 10008)
return message.channel.send('The ID supplied is not a message ID')
console.error(e)
return message.channel.send('An error occured while trying to move the message')
})
}
我收到一个TypeError: The resource must be a string or Buffer.
错误。如果尝试使用Buffer.from()
将其转换为缓冲区,则会收到TypeError: options.files.push is not a function
错误。
我该如何解决?