javascript - Discord.JS 机器人很慢,不知道为什么
问题描述
抱歉标题不好,我想不出一个好标题。
我正在运行一个自我机器人(我知道,针对 TOS,但我正在试验),它需要在发送时下载任何新文件(特别是图像 [gifs too] 和视频)。它确实有效,但速度很慢,而且下载的文件是几分钟前的。
这是我当前的代码:
const client = new Discord.Client();
let request = require(`request`);
let fs = require(`fs`);
function download(url, fname){
request.get(url)
.on('error', console.error)
.pipe(fs.createWriteStream("./cmc-memes/"+fname));
}
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
// lags idk why
client.on('message', msg => {
if (msg.channel.id === "296056831514509312") {
console.log(msg.content)
if(msg.attachments.first()){//checks if an attachment is sent
download(msg.attachments.first().url, msg.attachments.first().filename);//Function I will show later
}
}
});
我该怎么做才能解决这个问题?
任何帮助表示赞赏,谢谢!
解决方案
我不知道 request.get(url) 如何工作的细节(我更喜欢 node-fetch)但是如果它是一个同步调用,它会显着减慢它。否则问题只是您的互联网连接。
推荐阅读
- ios - 一旦安装到 Xcode 项目中,就不能使用可可豆荚模块
- r - 更改多个数据框中的变量类型
- c++ - std::apply 应用于模板函数中的构造函数
- antlr - ANTLR4 在输入端没有可行的替代方案
- java - 给定 n 个文件及其长度,将总字节数平均分配给 d 个线程,使得任何两个线程最多相差 1 个字节
- c++builder - std::variant 在赋值操作中给出 std@bad_alloc
- angular - 如何在角度货币管道中隐藏货币符号
- javascript - 对 Ember 计算属性相关键使用常量
- c# - 设置前景以编程方式查看
- python - Matplotlib xticks 与默认的重叠