javascript - 如何允许机器人在我的保管箱上创建文件/附加文件
问题描述
由于我的不和谐组经常有很多争议,所以我制作了一个机器人来按需记录聊天消息,以保留人们所说的话的证据。但是,由于机器人在 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
});
}
});
解决方案
推荐阅读
- c# - 使用反射的每个属性的 ValidationRule
- javascript - Angular 4使用渲染器在每个新行之前添加一个图像
- heroku - 如何在 Jhipster 应用程序中测量和减少您的内存使用?使用 Heroku 启动时
- android - 多值字符串格式Android
- angular - 如何在单击角度js中的链接时显示弹出窗口
- vuejs2 - 在 Vue 中隐藏卡片元素
- google-chrome - 创建 WebGL 上下文时出错。三个js chrome?
- java - 合并地图kotlin中的值
- android - 如何在片段中使用 ContextCompat?它说片段无法转换为上下文
- image - 检测内容感知填充的资源和方法