当我想做 !tfollow 命令时,我有错误 discord bot

时间:2021-05-02 21:41:53

标签: javascript discord bots

当我想要执行 !tfollow 命令时,我看到了,但我的朋友无法使用它 :( (节点:542)UnhandledPromiseRejectionWarning:未处理的承诺拒绝。这个错误要么是因为在没有 catch 块的情况下抛出了异步函数,要么是因为拒绝了一个没有用 .catch() 处理过的承诺。要在未处理的承诺拒绝时终止节点进程,请使用 CLI 标志 --unhandled-rejections=strict(请参阅 https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。 (拒绝编号:1) (节点:542)[DEP0018] 弃用警告:不推荐使用未处理的承诺拒绝。将来,未处理的承诺拒绝将以非零退出代码终止 Node.js 进程 请帮忙 这是脚本:

    fs = require('fs'),
    Discord = require('discord.js'),
    request = require('request'),
    client = new Discord.Client(),
    XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest,
    admins = ["yourid", "yourid", "yourid"],
    config = {
        "837586807403184162": 500,
        "837428085091074059": 200,
        "837427903595413524": 100,
        "837427193923239967": 75,
        "837426952562016276": 50,
        "837209894272630814": 25
    }

var express = require('express');
var app = express();
var tokens = fs.readFileSync('./tokens.txt', 'utf-8');
tokens = tokens.split("\n")

app.set('port', (process.env.PORT || 5000));
//For avoidong Heroku $PORT error
app.get('/', function (request, response) {
    var result = 'App is running'
    response.send(result);
}).listen(app.get('port'), function () {
    console.log('App is running, server is listening on port ', app.get('port'));
});

client.on('ready', async () => {
    console.log(`${client.user.tag} is ready !`)
    console.log(`Loaded ${tokens.length} tokens !`)
})

client.on('message', async (message) => {
    const prefix = "!";

    if (message.content.indexOf(prefix) !== 0) return;

    const args = message.content.slice(prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

    if (command === "pomoc") {
        message.channel.send(new Discord.MessageEmbed()
            .addFields({
                name: "Followers Booster",
                value: `\`${prefix}tfollow <twitch username>\``,
                inline: true
            }, {
                name: "Pomoc",
                value: `\`${prefix}pomoc\``,
                inline: true
            }, {
                name: "Opóźnienie bota",
                value: `\`${prefix}ping\``,
                inline: true

            }, {
                name: "Nuke (Mod Only)",
                value: `\`${prefix}nuke\``,
                inline: true

            }, {
                name: "Eval (Mod Only)",
                value: `\`${prefix}eval <code>\``,
                inline: true

            })
            .setColor("GREEN")
            .setFooter(message.guild.name, message.guild.iconURL({
                dynamic: true
            }))
        )
    }
    if (command === "ping") {
        message.channel.send(new Discord.MessageEmbed()
            .setDescription(`Mój ping to **${client.ws.ping}ms** !`)
            .setColor("GREEN")
            .setFooter(message.guild.name, message.guild.iconURL({
                dynamic: true
            }))
        )
    }
    if (command === "nuke") {
        const position = message.channel.position
        const channel = await message.channel.clone();
        message.channel.delete();
        channel.setPosition(position)
    }
    if (command === "eval" && admins.includes(message.author.id)) {
        const content = message.content.split(" ").slice(1).join(" ");
        const result = new Promise(async (resolve) => resolve(eval(content)));

        return result.then(async (output) => {
            if (typeof output !== "string") {
                output = require("util").inspect(output, {
                    depth: 0
                });
            }
            if (output.includes(client.token)) {
                output = output.replace(client.token, "T0K3N");
            }
            message.channel.send(output, {
                code: "js"
            });
        }).catch((err) => {
            err = err.toString();
            if (err.includes(client.token)) {
                err = err.replace(client.token, "T0K3N");
            }
            message.channel.send(err, {
                code: "js"
            });
            console.log(err)
        });
    }
    if (command === "tfollow") {
        let twitchID = "838010848835928064";

        if (admins.includes(message.author.id)) {

            if (!args[0]) return message.channel.send(new Discord.MessageEmbed().setColor('RED').setDescription("Musisz podać nazwę użytkownika Twitch !"))

            var roleID = Object.entries(config).find(([key, value]) => message.member.roles.cache.sort((a, b) => a.position - b.position).find(x => x.id === key))

            if (!roleID) roleID = [null, 0]

            await getUser(args[0]).then((res) => {
                if (res._total === 0) {
                    return message.channel.send(new Discord.MessageEmbed().setColor('RED').setDescription("Musisz podać**poprawną**nazwę użytkownika Twitch!"))
                } else {
                    twitchID = res.users[0]._id
                }
            })

            let number = args[1] ? parseInt(args[1]) : roleID[1] + 25
            follow(twitchID, number).then((cool) => {
                const channel = client.channels.cache.find(c => c.name === "?┇proofs");
                if (channel) channel.send(new Discord.MessageEmbed().setColor("GREEN").setAuthor(message.author.username, message.author.displayAvatarURL({
                    format: 'png',
                    dynamic: true,
                    size: 1024
                }))
                    .setFooter(message.guild.name, message.guild.iconURL({
                        dynamic: true
                    }))
                    .setDescription(`Pomyslnie dodano **${number}** obserwujących do \`${args[0]}\` (Twitch ID: \`${twitchID}\`)\n\nSprawdź kanał użytkownika [${args[0]} ](https://twitch.tv/${args[0]}/)`)).then((msg) => {
                        msg.react(":Verify:")
                    })
            })
            message.channel.send(new Discord.MessageEmbed().setColor('GREEN').setDescription(`Dodawanie **${number}** oserwujących do \`${args[0]}\` !`))
        } else if (!admins.includes(message.author.id)) {

            if (message.channel.id === client.channels.cache.find(c => c.name === "chat").id) return message.delete();

            var roleID = Object.entries(config).find(([key, value]) => message.member.roles.cache.sort((a, b) => a.position - b.position).find(x => x.id === key))

            if (!args[0]) return message.channel.send(new Discord.MessageEmbed().setColor('RED').setDescription("Musisz podać nazwę użytkownika Twitch!"))

            let number = 25

            if (roleID) {
                number = number + roleID[1]
            }

            await getUser(args[0]).then((res) => {
                if (res._total === 0) {
                    return message.channel.send(new Discord.MessageEmbed().setColor('RED').setDescription("Musisz określić **poprawną** nazwę użytkownika Twitch !"))
                } else {
                    twitchID = res.users[0]._id
                }
            })

            message.channel.send(new Discord.MessageEmbed().setColor('GREEN').setDescription(`Dodawanie **${number}** obserwujących do \`${args[0]}\` !`))

            follow(twitchID, number).then((cool) => {
                const channel = client.channels.cache.find(c => c.name === "?┇proofs");
                if (channel) channel.send(new Discord.MessageEmbed().setColor("GREEN").setAuthor(message.author.username, message.author.displayAvatarURL({
                    format: 'png',
                    dynamic: true,
                    size: 1024
                }))
                    .setFooter(message.guild.name, message.guild.iconURL({
                        dynamic: true
                    }))
                    .setDescription(`Pomyslnie dodano **${number}** obserwujących do \`${args[0]}\` (Twitch ID: \`${twitchID}\`)\n\nSprawdź kanał użytkownika [${args[0]}](https://twitch.tv/${args[0]}/)`)).then((msg) => {
                        msg.react(":Verify:")
                    })
            })
        }
    }
})

function getUser(username) {
    return fetch(`https://api.twitch.tv/kraken/users?login=${username}`, {
        method: "GET",
        headers: {
            'Client-ID': "ymd9sjdyrpi8kz8zfxkdf5du04m649",
            "Authorization": "OAuth wukbrnwp5f6uo4barxkzfpkacyugob",
            'Accept': 'application/vnd.twitchtv.v5+json'
        }
    }).then(async (res) => res.json())
};

async function follow(twitchID, number) {
    return new Promise(async (resolve, reject) => {
        let done = 0
        for (var i = 0; i < number; i++) {
            let res = await sendRequest(twitchID, tokens[i]);
            done++
        }

        while (i === number) {
            return resolve(true)
        }
    })

}

async function sendRequest(userid, token) {
    return new Promise(async (resolve, reject) => {
        var data = `[{"operationName":"FollowButton_FollowUser","variables":{"input":{"disableNotifications":false,"targetID":"` + userid + `"}},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"3efee1acda90efdff9fef6e6b4a29213be3ee490781c5b54469717b6131ffdfe"}}}]
    `;

        const options = {
            url: 'https://gql.twitch.tv/gql',
            headers: {
                "Authorization": 'OAuth ' + token,
                "Client-Id": 'kimne78kx3ncx6brgo4mv6wki5h1ko',
                "Content-Type": "application/json"
            },
            body: data
        };

        request.post(options, (err, res, body) => {
            if (err) {
                return console.log(`Nieprawidłowy token spróbuj z innymi tokenami, takimi jak tyogihfp9rueyo7vt4ple2wlihmlic`);
            }
            console.log(JSON.parse(body));
            resolve(true)
        });
    })
}

client.on("guildMemberAdd", async (member) => {
    const channels = ["?┇proofs", "?┇milktfollow®"]

    for (let i = 0; i < channels.length; i++) {
        const channel = client.channels.cache.find(c => c.name === channels[i])
        if (channel) channel.send(`${member}, **Sprawdź ten kanał!**`).then(async (msg) => {
            msg.delete({
                timeout: 1
            })
        })
    }
})

client.login("")```

0 个答案:

没有答案