首页 > 解决方案 > 如何允许机器人在我的保管箱上创建文件/附加文件

问题描述

由于我的不和谐组经常有很多争议,所以我制作了一个机器人来按需记录聊天消息,以保留人们所说的话的证据。但是,由于机器人在 heroku 上运行,我不能让机器人将日志转储到 github 中。我需要它附加到保管箱中的文件。如果文件不存在,请为我创建一个文件。

我不熟悉 Dropbox api,因此希望你们帮我完成代码。

ps 如果代码有任何问题/不好的部分,请随时帮助我改进它,这是我第一次创建机器人。

提前致谢

代码: https ://pastebin.com/asftq3zJ

const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require("fs");

//Options
const prefix = "!";
const documentation = "https://docs.google.com/spreadsheets/d/1dlUBQur9d8ANC-JJH6HA4gn4zxbFyz2xwQnTiPYZQi4/edit?usp=sharing"

//On Ready
client.on("ready",() => {
    console.log("JojoTheOtokonko is ready")
    client.user.setActivity("AV",{type: "WATCHING"});
});

//Login
client.login(process.env.token);

//Command Handler
client.on("message", async msg => {
    let message = msg.toString();
    let args = "";
    if(message[0] === prefix){
        args = message.substring(1).split(" ");
    }

    //Useful Commands
    //!a
    if(args[0] === "a"){
        let mentioned = msg.mentions.users.first();
        let server = args[1];
        await mentioned.send("Hello, Would you mind joining " + server + "?\nLove you :)");
    }

    //!record
    if(args[0] === "record" || args[0] === "rec"){
        recording = true;
        await msg.channel.send("@here Recoding message in " + msg.channel +" ,MIND YOUR LANGUAGE");
        await client.user.setActivity("to messages in " + msg.channel, {type: "LISTENING"});
    }

    if(args[0] === "record-stop" || args[0] === "rec-stop"){
        recording = false;
        await msg.channel.send("@here stopped recoding message in " + msg.channel);
        client.user.setActivity("AV",{type: "WATCHING"});
    }

    //help
    if(args[0] === "help"){
        await msg.reply("Full list of commands can be found at : \n" + documentation);
    }

    //Troll Commands
    //!ftl
    if(args[0] === "fti" || args[0] === "ftl"){
        let channel = msg.member.voice.channel
        if(!channel){
            return msg.channel.send("You need to be in a voice channel to use this command");
        }
        try {
            var connection = await channel.join();
        } catch (e) {
            console.log("Error connecting to voice channel");
        }
        connection.play('fti.mp3', { volume: 0.5 })
            .on("finish", () => channel.leave())
            .on("error", (error) => console.log(error));
    }

    if(args[0] === "fti-stop" || args[0] === "ftl-stop"){
        if(msg.member.voice.channel){
            msg.member.voice.channel.leave();
            await msg.channel.send("Successfully disconnected from voice , why dont you like Fire Three Island? TAT");
        }
    }

    //!elevator
    if(args[0] === "elevator"){
        await msg.channel.send("5_AvenueLocal");
    }

    //!innocity
    if(args[0] === "inno" || args[0] === "innocity"){
        await msg.channel.send("Is InnoCity Watersuno?");
    }
});

//Recorder
var recording = false;
client.on("message", msg =>{
    if(recording){
        let server = msg.guild.name;
        let appendata = "[" +Date.now()+"]" + "<" + msg.author.username + "> " + msg.toString() + "\n";
        fs.appendFile(server + ".txt", appendata, (err) => {
            if (err) throw err
        });
    }
});

标签: javascriptdiscord.jsdropbox

解决方案


推荐阅读