Discord Bot:如何将JS链接到PY

时间:2020-10-17 11:34:25

标签: javascript python node.js discord bots

我正在构建一个不和谐的机器人,我想添加战斗功能并根据用户的选择使其随机化,但是,我不知道如何让计算机知道某人是否已经使用了命令,是的,我确实知道JS中的“返回”功能,但随后我必须做出一个值以将我的当东西返回该东西之外。但是,然后我还必须让计算机知道用户是否已经进行了第一回合,我希望它包括三回合,直到警察来抓捕敌人为止,但是当我进行测试时,它说玩家健康和敌人的健康状况都是:“ NaN”,所以我想到了一个窍门,将一些命令链接到python,python有很多命令和许多原因,它可以导入python文件,但是我想将两者链接在一起,以便python操作命令,而javascript操作其他命令,但是我不知道该怎么做。这是所有代码。

---------------
Bot.JS :
var bal1 = 100
var bal2 = 100
var gb = 100
var bp = 0

var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
    colorize: true
});
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client({
   token: auth.token,
   autorun: true
});
bot.on('ready', function (evt) {
    logger.info('Connected');
    logger.info('Logged in as: ');
    logger.info(bot.username + ' - (' + bot.id + ')');
});
bot.on('message', function (user, userID, channelID, message, evt) {
    // Our bot needs to know if it will execute a command
    // It will listen for messages that will start with `>`
    if (message.substring(0, 1) == '>') {
        var args = message.substring(1).split(' ');
        var cmd = args[0];
       
        args = args.splice(1);
        switch(cmd) {
            // >ping
            case 'ping':
                bot.sendMessage({
                    to: channelID,
                    message: 'Pong!'
                });
            break;
            // >help
            case 'help':
                bot.sendMessage({
                    to: channelID,
                    message: 'Hello! umm.. this bot is being built right now... b-b-but....! here is all the commands available.....! \n >help, >ping, >bonk >bal >battle'
                })
            break;
            // >bonk
            case 'bonk':
                bot.sendMessage({
                    to: channelID,
                    message: '*Squishes You To The Size Of An Atom With A Bat* \n *****B O N K*****'
                })
            break;
            // >bal
            case 'bal':
                if(userID==546721227671076864) {
                    bot.sendMessage({
                        to: channelID,
                        message: bal2
                    })
                } 
                else if(userID==603873287071858701) {
                    bot.sendMessage({
                        to: channelID,
                        message: bal1
                    })
                }
                else {
                    bot.sendMessage({
                        to: channelID,
                        message: 'Global Money : ' + gm + ' (Note : It Resets Everytime the bot is shut down or daily'
                    })
                }
            break;
                }
                }
            // Just add any case commands if you want to..
            });
console.log("PROCESSING...")
var process = 1
while(process < 100) {
    while(process < 100) {
        process = process + 1
        console.log(process + "%")
    }
    if(process==25) {
        console.log("PROCESS 25% COMPLETE...")
    }
    if(process==50) {
        console.log("PROCESS 50% COMPLETE...")
    }
    if(process==75) {
        console.log("PROCESS 75% COMPLETE...")
    }
    if(process==90) {
        console.log("PROCESS 90% COMPLETE...")
    }
    if(process==91) {
        console.log("PROCESS 91% COMPLETE...")
    }
    if(process==92) {
        console.log("PROCESS 92% COMPLETE...")
    }
    if(process==93) {
        console.log("PROCESS 93% COMPLETE...")
    }
    if(process==94) {
        console.log("PROCESS 94% COMPLETE...")
    }
    if(process==95) {
        console.log("PROCESS 95% COMPLETE...")
    }
    if(process==96) {
        console.log("PROCESS 96% COMPLETE...")
    }
    if(process==97) {
        console.log("PROCESS 97% COMPLETE...")
    }
    if(process==98) {
        console.log("PROCESS 98% COMPLETE...")
    }
    if(process==99) {
        console.log("PROCESS 99% COMPLETE...")
    }
    if(process==100) {
        console.log("PROCESS 100% COMPLETE!")
    }
}

if(process==100) {
    console.log("'ZUNO' HAS STARTED.")
}

}
---------------
```#

0 个答案:

没有答案