Discord Bot Hogwarts点数机器人

时间:2018-06-23 14:40:14

标签: javascript bots discord points

一段时间以来,我一直在尝试使该机器人正常工作。我不是编码员,我对此主题的了解约为.002%。某些功能可以使用,但是在添加点时根本不起作用。

完全公开!!!! 这不是我的机器人。我找到了Here.

function housePointsFunc(args) {
    var house = this,

        user = args.message.member,
        roles = user.roles,

        canGivePoints = false,
        canTakePoints = false,
        canSetPoints = false;

    roles.map((value, index, arr) => {
        for (let i = 0; i < config.roles.doAllOfTheAbove.length; i++) {
            if (config.roles.doAllOfTheAbove[i] === value.name.toLowerCase()) {
                canGivePoints = true;
                canTakePoints = true;
                canSetPoints = true;
            }
        }

        
        if (!canTakePoints) {
            for (let i = 0; i < config.roles.takePoints.length; i++) {
                if (config.roles.takePoints[i] === value.name.toLowerCase()) {
                    canTakePoints = true;
                    break;
                }
            }
        }

        if (!canGivePoints) {
            for (let i = 0; i < config.roles.givePoints.length; i++) {
                if (config.roles.givePoints[i] === value.name.toLowerCase()) {
                    canGivePoints = true;
                    break;
                }
            }
        }

        if (!canSetPoints) {
            for (let i = 0; i < config.roles.setPoints.length; i++) {
                if (config.roles.setPoints[i] === value.name.toLowerCase()) {
                    canSetPoints = true;
                    break;
                }
            }
        }
    });

    var firstParam = args.params[0];
    if (firstParam !== undefined) {
        if (firstParam.toLowerCase !== undefined) {
            firstParam = firstParam.toLowerCase();
        }
    }

    if (firstParam === 'points' || firstParam === 'point' || firstParam === 'p' || firstParam === undefined) {
        args.send(house.capitalize() + ' has ' + points[house] + ' point(s)!');
    } else if ((firstParam === 'add' || firstParam === 'increase' || firstParam === '+' || firstParam === 'give') && canGivePoints === true) {
        if (isNaN(args.params[1]) || args.params[1] === 'Infinity' || args.params[1] === '-Infinity') {
            args.send(' ' + args.params[1] + ' is not a number!');
        } else {
            points[house] += Number(args.params[1]);
            if (points[house] < 0) {
                points[house] = 0;
            }
            args.send('Added ' + args.params[1] + ' point(s) to ' + house.capitalize() + '!\n' + house.capitalize() + ' has ' + points[house] + ' point(s) now!');
            writeJSON(__dirname + '/JSON/points.json', points);
        }
    } else if ((firstParam === 'subtract' || firstParam === 'sub' || firstParam === 'decrease' || firstParam === '-' || firstParam === 'take') && canTakePoints === true) {
        if (isNaN(args.params[1]) || args.params[1] === 'Infinity' || args.params[1] === '-Infinity') {
            args.send(' ' + args.params[1] + ' is not a number!');
        } else {
            points[house] -= Number(args.params[1]);
            if (points[house] < 0) {
                points[house] = 0;
            }
            args.send('Subtracted ' + args.params[1] + ' point(s) from ' + house.capitalize() + '!\n' + house.capitalize() + ' has ' + points[house] + ' point(s) now!');
            writeJSON(__dirname + '/JSON/points.json', points);
        }
    } else if ((firstParam === 'set' || firstParam === 'setas') && canSetPoints === true) {
        if (isNaN(args.params[1]) || args.params[1] === 'Infinity' || args.params[1] === '-Infinity') {
            args.send(' ' + args.params[1] + ' is not a number!');
        } else {
            points[house] = Number(args.params[1]);
            if (points[house] < 0) {
                points[house] = 0;
            }
            args.send('Set ' + house.capitalize() + " house's points to " + args.params[1] + '!\n' + house.capitalize() + ' has ' + points[house] + ' point(s) now!');
            writeJSON(__dirname + '/JSON/points.json', points);
        }

这是我遇到问题的代码。 (或者至少我认为是。)

我也一直在尝试找出如何将该机器人的功能限制为仅某些角色,但这又是一天!哈哈。任何人都可以看到这里出了什么问题吗?是我想念的东西吗?

哦,是的,我试图找到创建者的联系信息,但是我在任何地方都找不到。 -叹气-

任何帮助将不胜感激。

谢谢, 拉齐

0 个答案:

没有答案