Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_UNHANDLED_REJECTION #378

Open
Av1anJay opened this issue Feb 28, 2022 · 0 comments
Open

ERR_UNHANDLED_REJECTION #378

Av1anJay opened this issue Feb 28, 2022 · 0 comments

Comments

@Av1anJay
Copy link

Av1anJay commented Feb 28, 2022

When i type create command:
Screenshot_2022-03-01-03-41-36-286_com realvnc viewer android
Can i use on raspberry pi or repl.it?

Code:

// Load modules
const Discord = require("discord.js"),
backup = require("discord-backup"),
client = new Discord.Client(),
settings = {
    prefix: "ab=",
    token: "TOKEN"
};

client.on("ready", () => {
    console.log("bot started.");
});

client.on("message", async message => {

    // This reads the first part of your message behind your prefix to see which command you want to use.
    let command = message.content.toLowerCase().slice(settings.prefix.length).split(" ")[0];

    // These are the arguments behind the commands.
    let args = message.content.split(" ").slice(1);

    // If the message does not start with your prefix return.
    // If the user that types a message is a bot account return.
    // If the command comes from DM return.
    if (!message.content.startsWith(settings.prefix) || message.author.bot || !message.guild) return;

    if(command === "create"){
        // Check member permissions
        if(!message.member.hasPermission("ADMINISTRATOR")){
            return message.channel.send(":x: | 你需要是一個管理員來備份!");
        }
        // Create the backup
        backup.create(message.guild, {
            jsonBeautify: true
        }).then((backupData) => {
            // And send informations to the backup owner
            message.author.send("要還原,請執行此指令。")
            message.author.send("`"+settings.prefix+"load "+backupData.id+"`");
            message.channel.send(":white_check_mark: 已完成備份,請查看你的私人訊息。");
        });
    }

    if(command === "load"){
        // Check member permissions
        if(!message.member.hasPermission("ADMINISTRATOR")){
            return message.channel.send(":x: | 你需要是一個管理員來載入備份!");
        }
        let backupID = args[0];
        if(!backupID){
            return message.channel.send(":x: | 你需要輸入一個正確的備份ID!");
        }
        // Fetching the backup to know if it exists
        backup.fetch(backupID).then(async () => {
            // If the backup exists, request for confirmation
            message.channel.send(":warning: | 將會清除所有伺服器內所有內容並載入備份!輸入yes來載入!");
                await message.channel.awaitMessages(m => (m.author.id === message.author.id) && (m.content === "yes"), {
                    max: 1,
                    time: 20000,
                    errors: ["time"]
                }).catch((err) => {
                    // if the author of the commands does not confirm the backup loading
                    return message.channel.send(":x: | 時間已到!載入備份已取消。");
                });
                // When the author of the command has confirmed that he wants to load the backup on his server
                message.author.send(":white_check_mark: | Start loading the backup!");
                // Load the backup
                backup.load(backupID, message.guild).then(() => {
                    // When the backup is loaded, delete them from the server
                    backup.remove(backupID);
                }).catch((err) => {
                    // If an error occurred
                    return message.author.send(":x: | 有什麼地方好像出錯了...請檢查我是否有管理員權限!");
                });
        }).catch((err) => {
            console.log(err);
            // if the backup wasn't found
            return message.channel.send(":x: | 找不到備份 `"+backupID+"`!");
        });
    }

    if(command === "infos"){
        let backupID = args[0];
        if(!backupID){
            return message.channel.send(":x: | 這不是正確的備份ID!");
        }
        // Fetch the backup
        backup.fetch(backupID).then((backupInfos) => {
            const date = new Date(backupInfos.data.createdTimestamp);
            const yyyy = date.getFullYear().toString(), mm = (date.getMonth()+1).toString(), dd = date.getDate().toString();
            const formatedDate = `${yyyy}/${(mm[1]?mm:"0"+mm[0])}/${(dd[1]?dd:"0"+dd[0])}`;
            let embed = new Discord.MessageEmbed()
                .setAuthor("備份資訊")
                // Display the backup ID
                .addField("備份ID", backupInfos.id, false)
                // Displays the server from which this backup comes
                .addField("伺服器ID", backupInfos.data.guildID, false)
                // Display the size (in mb) of the backup
                .addField("檔案大小", `${backupInfos.size} kb`, false)
                // Display when the backup was created
                .addField("創建日期", formatedDate, false)
                .setColor("#FF0000");
            message.channel.send(embed);
        }).catch((err) => {
            // if the backup wasn't found
            return message.channel.send(":x: | 找不到備份 `"+backupID+"`!");
        });
    }

});

//Your secret token to log the bot in. (never share this to anyone!)
client.login(settings.token);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant