Node.js 如何将本地文件附加到嵌入文件?

Node.js 如何将本地文件附加到嵌入文件?,node.js,discord.js,Node.js,Discord.js,如果你想知道的话,discord.js的版本是12.2.0。 我想在第三个嵌入文件上附加一个图像忽略嵌入文件的标题我稍后会尝试处理它,它是一个名为role5的本地文件。但我似乎无法将该文件附加到嵌入文件。事情就是这样 const Discord = require('discord.js'); const {Client, MessageAttachment} = require('discord.js'); const bot3 = new Client(); const mark2 =

如果你想知道的话,discord.js的版本是12.2.0。 我想在第三个嵌入文件上附加一个图像忽略嵌入文件的标题我稍后会尝试处理它,它是一个名为role5的本地文件。但我似乎无法将该文件附加到嵌入文件。事情就是这样

const Discord = require('discord.js');
const {Client, MessageAttachment} = require('discord.js');
const bot3 = new Client();


const mark2 = '*info personal'
const mark3 = '*info guild'
const mark4 = '*info roles'
bot3.on('message', msg =>{

    if (msg.content.startsWith(mark2)){
        const hashitag = msg.author.id
        const actualhashitag = msg.author.discriminator
        const evenbetterhashitag = "#" + actualhashitag 
        const personalembed = new Discord.MessageEmbed()
            .setTitle('Stuff about you')
            .setImage(msg.author.displayAvatarURL())
            .setColor('#D11111')
            .addField('Your username',  msg.author.username)
            .addField('Your hashtag', hashitag, true)
            .addField('Your actual hashtag', actualhashitag, true)
            .addField('Your even realer hashtag', evenbetterhashitag, true)   
            .addField('Your amount of friends', 'Discord bots can not know that sadly')
            .addField('Your role', msg.member.roles.cache.map(role => role.name).join(", ") )
            .addField('Your role id', msg.member.roles.cache.map(role => role.id).join(", ") )
            .addField('Your nickname', msg.member.nickname);
        msg.channel.send(personalembed)
    }
    if (msg.content.startsWith(mark3)){




        const guildembed = new Discord.MessageEmbed()

            .setTitle(msg.guild.name)
            .setImage(msg.guild.iconURL())
            .setColor('#97FF00')
            .addField('the id of the server', msg.guild.id)
            .addField('the owner', msg.guild.owner.user.username)
            .addField('the owner tag', msg.guild.owner.user.tag)
            .addField('the owner id', msg.guild.ownerID)
            .addField('the owner nickname', msg.guild.owner.nickname)
            .addField('all roles', msg.guild.roles.cache.map(role => role.name).join(", ") ) 
            .addField('the bots', msg.guild.members.cache.filter(member => member.user.bot).map(member => member.user.tag).join(' | '))
            .addField('the bots actual name', msg.guild.members.cache.filter(member => member.user.bot).map(member => member.user.username).join(' | '))
            .addField('the bot ids', msg.guild.members.cache.filter(member => member.user.bot).map(member => member.user.id).join(' | '))
            .addField('the bots hashtag(without the hashtag)', msg.guild.members.cache.filter(member => member.user.bot).map(member => member.user.discriminator).join(' | '))
        msg.channel.send(guildembed)

    }  

    if(msg.content.startsWith(mark4)){
        const attachmento = new MessageAttachment('./stuff\role5.png', 'name') 
        const roleembed = new Discord.MessageEmbed()
            .setTitle('All roles and the people with the roles')
            .attachFiles(attachmento)
            .setThumbnail(attachmento)
            .setColor('FFA737')
        msg.channel.send(roleembed)
    }


})

bot3.login(process.env.token3)
从中,创建嵌入时,需要使用.attachFiles将本地文件附加到嵌入。之后,你可以使用ttachment://fileName.extension 设置嵌入图像/图标时

嵌入角色的示例:

2020-06-17T11:33:33.792109+00:00 heroku[Worker.1]: State changed from up to starting
2020-06-17T11:33:34.000000+00:00 app[api]: Build succeeded
2020-06-17T11:33:35.043286+00:00 heroku[Worker.1]: Stopping all processes with SIGTERM
2020-06-17T11:33:35.136963+00:00 heroku[Worker.1]: Process exited with status 143
2020-06-17T11:33:35.621163+00:00 heroku[Worker.1]: Starting process with command `node index.js`
2020-06-17T11:33:36.314618+00:00 heroku[Worker.1]: State changed from starting to up
2020-06-17T11:33:38.193183+00:00 app[Worker.1]: This bot is online
2020-06-17T11:34:17.887173+00:00 app[Worker.1]: (node:4) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, stat '/app/stuff
2020-06-17T11:34:17.887251+00:00 app[Worker.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
2020-06-17T11:34:17.887307+00:00 app[Worker.1]: (node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

哦,这就是我做错的地方。我以前不需要这个角色。好啊有道理。不过还有一个问题。是否有办法使缩略图更大,以便更容易看到。我知道使用setImage而不是setThumbnail会使它变大,但我希望它在开始时而不是结束时。
const roleembed = new Discord.MessageEmbed()
            .setTitle('All roles and the people with the roles')
            .attachFiles('./stuff/role5.png')
            .setThumbnail("attachment://role5.png")
            .setColor('FFA737')
        msg.channel.send(roleembed)