javascript - Discord虚荣狙击机器人错误:没有这样的文件或目录
问题描述
下面的代码是我想在 replit.com 上运行的这个不和谐的虚荣狙击机器人。
它显示错误。
错误:
internal/fs/utils.js:269
抛出错误;
^错误:
ENOENT:没有这样的文件或目录, 在 Object.readFileSync (fs.js:364:35)的
Object.openSync (fs.js:462:3) 处打开“/home/runner/RudePartialBuckets/index.js”目的。(/run_dir/interp.js:195:19) 在 Module._compile (internal/modules/cjs/loader.js:999:30) 在 Object.Module._extensions..js (internal/modules/cjs/loader.js :1027:10) 在 Module.load (internal/modules/cjs/loader.js:863:32) 在 Function.Module._load (internal/modules/cjs/loader.js:708:14) 在 Function.executeUserEntryPoint [ as runMain] (internal/modules/run_main.js:60:12) at internal/main/run_main_module.js:17:47 { errno: -2, syscall: 'open', code: 'ENOENT',
路径:'/home/runner/RudePartialBuckets/index.js'
}
代码:
const Discord = require('discord.js'),
client = new Discord.Client(),
moment = require("moment-timezone"),
fetch = require('node-fetch');
class Main {
constructor() {
this.sniperInterval;
}
async setVanityURL(url, guild) {
const time = moment.tz(Date.now(), "Europe/Paris").format("HH:mm:ss");
console.log(`[${time}] [LOG] Sniping discord.gg/${url}`);
return await fetch(`https://discord.com/api/v8/guilds/${guild.id}/vanity-url`, {
"credentials": "include",
"headers": {
"accept": "*/*",
"authorization": "Bot " + client.token,
"content-type": "application/json",
},
"referrerPolicy": "no-referrer-when-downgrade",
"body": JSON.stringify({
"code": url
}),
"method": "PATCH",
"mode": "cors"
});
}
async checkVanityURL(url) {
return await fetch(`https://discord.com/api/v8/guilds/${guild.id}/vanity-url`, {
"credentials": "include",
"headers": {
"accept": "*/*",
"authorization": "Bot " + client.token,
"content-type": "application/json",
},
"referrerPolicy": "no-referrer-when-downgrade",
"method": "GET",
"mode": "cors"
});
}
async startSnipe(url, guild) {
this.sniperInterval = setInterval(async () => {
await this.setVanityURL(url, guild);
}, 1000);
}
stopSnipe() {
return clearInterval(this.sniperInterval);
}
}
const prefix = ".";
let handler = new Main();
client.on('message', async (message) => {
let messageArray = message.content.split(" "),
args = messageArray.slice(1);
const args1 = message.content.slice(prefix.length).split(/ +/),
command = args1.shift().toLowerCase();
if (command === "start-snipe") {
let url = args[0];
if (!message.guild.features.includes('VANITY_URL')) {
return message.reply("You don't have level 3 boost !");
};
message.reply(`Start sniping the url ${url} now!`);
console.log(`[LOG] Start sniping the url ${url} now!`);
await handler.startSnipe(url, message.guild);
};
if (command === "stop-snipe") {
handler.stopSnipe();
};
});
client.login("YOUR BOT TOKEN");
解决方案
如果我重命名 replit.com 在启动新项目 (repl) 时创建的 index.js 文件,我能够重现此错误。确保您的代码位于名为 index.js 的文件中,因为这是您的应用程序的入口点。
推荐阅读
- haproxy - HaProxy 保持连接的 sourceIP
- python - 如何使用 Python Regex Exact Match 提取子字符串
- lua - 在罗技 5.4 LUA 中弃用 table.getn 后,此代码似乎不再起作用
- java - Java中二叉搜索树的add方法
- php - 对多维产品数组进行排序的逻辑
- c# - 如何从 Zebra 标签打印机获取标签尺寸
- java - 由于 startforeground 通知错误,应用程序崩溃
- javascript - 从数组到对象数组的结构格式
- javascript - Javascript deleteRule() 无法正常运行
- ios - iOS WKWebView 的 didCommitNavigation 从未调用过?