Javascript 在heroku上安装npm包

Javascript 在heroku上安装npm包,javascript,java,node.js,Javascript,Java,Node.js,我有一个自定义的discord机器人。我为Node.js下载了这个额外生命API。在我的PC上本地工作非常完美,因为它可以读取API所在的node_modules文件夹 我在commands文件夹中创建了一个extralife.js文件。我正在使用模块 我的机器人正在云上运行(heroku),从github获取代码,但它无法使用此API 我想知道如何在heroku上安装这个额外生命API来使用我的命令,就像在我的PC上一样 感谢您的帮助 问候 代码: const{prefix}=require(

我有一个自定义的discord机器人。我为Node.js下载了这个额外生命API。在我的PC上本地工作非常完美,因为它可以读取API所在的node_modules文件夹

我在commands文件夹中创建了一个extralife.js文件。我正在使用模块

我的机器人正在云上运行(heroku),从github获取代码,但它无法使用此API

我想知道如何在heroku上安装这个额外生命API来使用我的命令,就像在我的PC上一样

感谢您的帮助

问候

代码:

const{prefix}=require('../config.json');//config.json是一个文件夹。。
const extralifeapi=require('extra-life-api');
module.exports={
//名称:、冷却时间:、参数:和描述:是对象的属性。它们对于在主文件上使用很重要。
名称:'extralife',
冷却时间:5,
描述:'extralife!',
//无论何时在命令文件中将args设置为true,它都将执行此检查并在必要时提供反馈。
阿格斯:没错,
用法:“+”,
参数:“,”,
执行(消息,参数){
如果(参数[0]=“信息”){
extralifeapi.getUserInfo('349069')。然后(userinfo=>{
return msg.channel.send(`Participant name:${userinfo.displayName}\nExtra Life team is:${userinfo.teamName}\n募捐目标:${userinfo.fundraisingGoal}`);
});
}else if(参数[0]=“团队”){
让args1=msg.content.slice(prefix.length.split(+/);
const extralifTeamid=args1[2]
extralifeapi.getTeamInfo(`${extralifTeamid}`)。然后(teaminfo=>{
返回msg.channel.send(`Team name:${teaminfo.name}\n团队队长:${teaminfo.captainDisplayName}\n募捐目标:${teaminfo.fundraisingGoal}\n募捐页面:${teaminfo.links.Page}\n`);
});
}else if(参数[0]='schedule'){
return msg.reply('额外生命流团队计划:https://community.extra-life.org/forums/topic/4508-the-official-extra-life-stream-team-weekly-schedule/');
}else if(args[0]=“捐助者”){
让args1=msg.content.slice(prefix.length.split(+/);
const extralifeid=args1[2]
extralifeapi.getUserAdivations(`${extralifeid}`)。然后(捐款=>{
return msg.channel.send(`Total participant捐款募集:${Adivations.CountAdivations}\n`);
});
}else if(args[0]=“Team捐助者”){
让args1=msg.content.slice(prefix.length.split(+/);
const extralifeid=args1[2]
extralifeapi.getteam捐款(`${extralifeid}`)。然后(捐款=>{
return msg.channel.send(`Total team investments raised:${investments.countinvestments}\n团队ID:${investments.investments[0].teamID}\n`);
});
}else if(参数[0]=“参与者”){
让args1=msg.content.slice(prefix.length.split(+/);
const extralifeid=args1[2]
getUserInfo(`${extralifeid}`)。然后(userinfo=>{
return msg.channel.send(`Participant name:${userinfo.displayName}\nExtra-Life-team-is:${userinfo.teamName}\nExtra-Life-team-ID:${userinfo.teamID}\n募捐目标:${userinfo.fundraisingGoal}\n募捐页面:${userinfo.links.provate}\n流页面:${userinfo.links.stream});
});
如果(!args[0]=''){
return msg.reply('你需要一个额外的生命id才能使用这个命令');
}
//返回msg.channel.send(`youwanttoplayingrounds?${taggedUser.username}`);
}
//msg.channel.send(`此参数对于此命令不正确,请重试:${args[0]}`);
},
};

Heroku应该像在机器上一样自动运行
npm安装(获取package.json中的所有库),所以这很奇怪。检查heroku日志,您是否看到任何错误?您好。我应该如何在package.json上声明这个库,因为我没有声明,而且工作正常。我在我的电脑上下载了一个特定的命令:npm I extra-life api
npm I extra-life api
应该足够了,因为它会自动将依赖项写入package.json中。你能发布你的package.json的内容和使用该库的代码吗?我在我的主\DiscordBot\文件夹中找到了两个,其中一个在node_modules\extra life api上,有很多信息,这是在通过NPM安装api后的api文件夹中。在这里发布太长了。@Michele我修复了在我的package.json上添加依赖项的问题。Heroku自动部署了API。非常感谢!!!Heroku应该自动运行
npm安装
,就像您在机器上所做的那样(获取package.json中的所有库),所以这很奇怪。检查heroku日志,您是否看到任何错误?您好。我应该如何在package.json上声明这个库,因为我没有声明,而且工作正常。我在我的电脑上下载了一个特定的命令:npm I extra-life api
npm I extra-life api
应该足够了,因为它会自动将依赖项写入package.json中。你能发布你的package.json的内容和使用该库的代码吗?我在我的主\DiscordBot\文件夹中找到了两个,其中一个在node_modules\extra life api上,有很多信息,这是在通过NPM安装api后的api文件夹中。在这里发布太长了。@Michele我修复了在我的package.json上添加依赖项的问题。Heroku自动部署了API。非常感谢!!!
const { prefix } = require('../config.json'); // config.json is one folfer up ..
const extralifeapi = require('extra-life-api');

module.exports = {
    //name:, cooldown:, args: and description: are properties of the object. They are important to use on the main file.

    name: 'extralife',
    cooldown: 5,
    description: 'extralife!',
    //whenever you set args to true in one of your command files, it'll perform this check and supply feedback if necessary.
    args: true,
    usage: '+ <ARGUMENT>',
    arguments: '<info>, <team + teamID>, <teamdonors + teamID>, <donors + participantID>, <participant + participantID>',
    execute(msg, args) {
        if (args[0] === 'info') {
            extralifeapi.getUserInfo('349069').then(userinfo => {
                return msg.channel.send(`Participant name: ${userinfo.displayName}\nExtra Life team is: ${userinfo.teamName}\nFunraising Goal: ${userinfo.fundraisingGoal}`);
            });
        } else if (args[0] === 'team') {
            let args1 = msg.content.slice(prefix.length).split(/ +/);
            const extralifTeamid = args1[2]
            extralifeapi.getTeamInfo(`${extralifTeamid}`).then(teaminfo => {
                return msg.channel.send(`Team name: ${teaminfo.name}\nTeam Captain: ${teaminfo.captainDisplayName}\nFunraising Goal: ${teaminfo.fundraisingGoal}\nFunraising Page: ${teaminfo.links.page}\n`);
            });
        } else if (args[0] === 'schedule') {
            return msg.reply('Extra Life stream team schedule: https://community.extra-life.org/forums/topic/4508-the-official-extra-life-stream-team-weekly-schedule/');
        }else if (args[0] === 'donors') {
            let args1 = msg.content.slice(prefix.length).split(/ +/);
            const extralifeid = args1[2]
            extralifeapi.getUserDonations(`${extralifeid}`).then(Donations => {
                return msg.channel.send(`Total participant donations raised: ${Donations.countDonations}\n`);
            });
        } else if (args[0] === 'teamdonors') {
            let args1 = msg.content.slice(prefix.length).split(/ +/);
            const extralifeid = args1[2]
            extralifeapi.getTeamDonations(`${extralifeid}`).then(Donations => {
                return msg.channel.send(`Total team donations raised: ${Donations.countDonations}\nTeam ID: ${Donations.donations[0].teamID}\n`);
            });
        } else if (args[0] === 'participant') {
            let args1 = msg.content.slice(prefix.length).split(/ +/);
            const extralifeid = args1[2]
            extralifeapi.getUserInfo(`${extralifeid}`).then(userinfo => {
                return msg.channel.send(`Participant name: ${userinfo.displayName}\nExtra Life team is: ${userinfo.teamName}\nExtra Life Team ID: ${userinfo.teamID}\nFunraising Goal: ${userinfo.fundraisingGoal}\nFunraising Page: ${userinfo.links.donate}\nStream Page: ${userinfo.links.stream} `); 
            });
            if (!args[0] === '') {
                return msg.reply('Human you need an Extra Life id in order to use this command');
            }
            //return msg.channel.send(`Do you want to play some rounds? ${taggedUser.username}`);
        }
        //msg.channel.send(`This argument is incorrect for this command, try again human: ${args[0]}`);
    },
};