首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我不知道我遗漏了什么模块

我不知道我遗漏了什么模块
EN

Stack Overflow用户
提问于 2021-01-10 19:08:38
回答 1查看 80关注 0票数 1

好的,下面是我的代码:

代码语言:javascript
复制
const mineflayer = require("mineflayer");
const discord = require("discord.js");
const config = require("./config.json");
const colors = require("colors");

const client = new discord.Client({autoReconnect: true});
const options = {
    host: 'mc.hypixel.net',
    port: 25565,
    version: '1.8.9',
    username: config["minecraft-username"],
    password: config["minecraft-password"],
};

// minecraft bot stuff vv
let mc;
(function init() {
    console.log("Logging in.");
    mc = mineflayer.createBot(options);
    mc._client.once("session", session => options.session = session);
    mc.once("end", () => {
        setTimeout(() => {
            console.log("Connection failed. Retrying..");
            init();
        }, 60000);
    });
}());

let uuid;
let name;
mc.on("login", () => {
    uuid = mc._client.session.selectedProfile.id;
    name = mc._client.session.selectedProfile.name;
    setTimeout(() => {
        console.log("Sending to limbo.");
        mc.chat("/achat \u00a7c<3");
    }, 1000);
    mc.chat("/gc Logged in")
});

mc.on("message", (chatMsg) => {
    const msg = chatMsg.toString();
    console.log("Minecraft: ".brightGreen + msg);
    if (msg.endsWith(" joined the lobby!") && msg.includes("[MVP+")) {
        console.log("Sending to limbo.");
        mc.chat("/achat \u00a7ca");
        return;
    }

    if (msg.startsWith("Guild >") && msg.includes(":")) {
        let v = msg.split(" ", 2);
        if (v[2].includes(name + ":") || v[3].includes(name + ":")) return;

        let splitMsg = msg.split(" ");
        let i = msg.indexOf(":");
        let splitMsg2 = [msg.slice(0,i), msg.slice(i+1)];
        let sender, sentMsg;
        if (splitMsg[2].includes("[")) {
            sender = splitMsg[3].replace(":","");
        } else {
            sender = splitMsg[2].replace(":","");
        }
        sentMsg = splitMsg2[1];

        let embed = new discord.RichEmbed()
            .setAuthor(sender + ": " + sentMsg, "https://www.mc-heads.net/avatar/" + sender)
            .setColor("GREEN");

        //channel.send(embed);
        client.guilds.get(config["discord-guild"]).channels.get(config["discord-channel"]).send(embed);
    }
});

// discord bot stuff vv
client.on("ready", () => {
    console.log("Discord: Logged in.".bgBlue);
});

client.on("message", (message) => {
    if (message.channel.id !== config["discord-channel"] || message.author.bot || message.content.startsWith(config["discord-bot-prefix"])) return;
    console.log("Discord: ".blue + message.author.username + ": " + message.content);
    mc.chat("/gc d. " + message.author.username.replace(" ", "") + ": " + message.content);
});

client.login(config["discord-token"]);

下面是我的package.js文件:

代码语言:javascript
复制
{
  "name": "discord-hypixel-bridge",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "Squag",
  "license": "GPL-3.0",
  "dependencies": {
    "discord.js": "^12.5.1",
    "mineflayer": "^2.40.0",
    "colors": "^1.4.0",
    "follow-redirects": "^1.13.1",
    "safe-buffer": "^5.2.1",
    "nearley": "^2.20.0"
  }
}

下面是我得到的错误:

Check /app/package.json: command not found. Is a start script missing?

有人能帮我一下吗?

EN

回答 1

Stack Overflow用户

发布于 2021-01-10 20:44:58

为了使用npm start运行项目,您需要将scripts对象添加到package.json中。此外,您的文件当前名为package.js,因此请确保将其重命名为package.json

代码语言:javascript
复制
{
  "name": "discord-hypixel-bridge",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "Squag",
  "license": "GPL-3.0",
  "dependencies": {
    "discord.js": "^12.5.1",
    "mineflayer": "^2.40.0",
    "colors": "^1.4.0",
    "follow-redirects": "^1.13.1",
    "safe-buffer": "^5.2.1",
    "nearley": "^2.20.0"
  },
  "scripts": {
    "start": "node ."
  }
}

有关npm docs的更多信息。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65652583

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档