PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
5.07k stars 919 forks source link

Mineflayer wont work at all or join the server #2118

Closed Tofaa2 closed 3 years ago

Tofaa2 commented 3 years ago

Versions

Detailed description of a problem

A clear and concise description of what the problem is, with as much context as possible. What are you building? What problem are you trying to solve?

Trying to make a bridge bot from a discord channel to a hypixel guild chat but the bot wont even connect to the lobby

What did you try yet?

Did you try any method from the API? Yes Did you try any example? Any error from those? Yes i have "https://hypixel.net/threads/guide-making-a-discord-to-guild-bot.4219994/"

Your current code

// INDEX.JS
const mineflayer = require('mineflayer');

const bot = mineflayer.createBot({
  host: 'mc.hypixel.net', 
  username: "email",
  password: "password"
})

module.exports = {bot, client};
fs.readdir('./mineflayer/', (err, files) => { 
    if (err) return console.error(err); 
    files.forEach(file => {
        if (!file.endsWith('.js')) return;
        const event = require(`./mineflayer/${file}`);
        const eventName = file.split('.')[0];
        bot.on(eventName, event.bind(null, bot));
    })
})
// ./mineflayer/message.js
const Discord = require('discord.js');
const config = require('../config.json');
const { client } = require('../index.js');
const fetch = require('node-fetch'); 

module.exports = async (bot, jsonMsg, position) => {
    fetch(`https://api.mojang.com/users/profiles/minecraft/${(jsonMsg.extra && jsonMsg.text == 'Guild > ' && (jsonMsg.extra[1].text == 'left.' || jsonMsg.extra[1].text == 'joined.')) ? jsonMsg.extra[0].text.replace(/[ ]/g, '') : "steve"}`)
    .then(res => res.json())
    .then(data => {

    let uuid = data.id ? data.id : "8667ba71b85a4004af54457a9734eed7" // Defaults to the steve skin UUID if not found
    const gchannel = client.channels.cache.get('839273041166073907'); // The guild channel
    // Join embed
    const joinEmbed = new Discord.MessageEmbed()
    .setColor(config.GREEN)
    .setAuthor(`${jsonMsg.extra ? jsonMsg.extra[0].text : null}is now online.`, `https://crafatar.com/avatars/${uuid}.png`);
    // Leave embed
    const leaveEmbed = new Discord.MessageEmbed()
    .setColor(config.RED)
    .setAuthor(`${jsonMsg.extra ? jsonMsg.extra[0].text : null}is now offline.`, `https://crafatar.com/avatars/${uuid}.png`);
    // If Message starts with guild
    if (jsonMsg.text == 'Guild > ' && jsonMsg.extra[1].text == 'left.') {
        gchannel.send(leaveEmbed);
    } else if (jsonMsg.text == 'Guild > ' && jsonMsg.extra[1].text == 'joined.') {
        gchannel.send(joinEmbed);
    }

    if (jsonMsg.extra) {
        if (jsonMsg.text == '' && jsonMsg.extra[0].text.startsWith('§2Guild > ')) {
            // Guild messages have the color codes built in, opposed to join messages, so we have to get rid of those.
            let username = jsonMsg.extra ? jsonMsg.extra[0].text.replace('§2Guild > ', '').replace(/§7/g, '').replace(/§f/g, '').replace(/§3/g, '').replace(/§a/g, '').replace(/§6/g, '').replace(/§b/g, '').replace(/§d/, '').replace(/§c/g, '').replace(/§d/g, '').replace(/§e/g, '').replace(/§1/g, '').replace(/§0/g, '').replace(/§2/g, '').replace(/§4/g, '').replace(/§5/g, '').replace(/§8/g, '').replace(/§9/g, '').replace('[VIP] ', '').replace('[VIP+]', '').replace('[MVP]', '').replace('[MVP+]', '').replace('[MVP++]', '').replace('[P]', '').replace('[DGD]', '').replace('[GM]', '').replace('[BG]', '').replace('[EX]', '').replace('[GD]', '').replace(' :', '') : null;
            // Fetch the message (if it exists)
            let msg = jsonMsg.extra ? jsonMsg.extra[1].text : null;

            // Detects if username fetch and message fetch were sucessful
            if (username !== null && msg !== null) {
                // Used to get the player's uuid for the image using the username
                fetch(`https://api.mojang.com/users/profiles/minecraft/${username.replace(/[ ]/g, '')}`)
                .then(res => res.json())
                .then(p => {
                // Message Embed
                const messageEmbed = new Discord.MessageEmbed()
                .setColor(config.GREEN)
                .setAuthor(username, `https://crafatar.com/avatars/${p.id}.png`)
                .setDescription(msg)
                .setFooter("Phazence Discord to Hypixel bridge bot")
                .setTimestamp();
                gchannel.send(messageEmbed);
                })
                // Test command used inside the guild
                // Activated by '/gc /ping'
                if (msg.toLowerCase() == '/ping' || msg.toLowerCase() == '-ping') {
                    bot.chat(`/gc Pong! Latency is ${bot.player.ping}ms.`);
                }
            }
        }
    }
    })
}

Expected behavior

A clear and concise description of what you expected to happen.

Additional context

Add any other context about the problem here.

builder-247 commented 3 years ago

I believe you need to specify a version for your bot

nickelpro commented 3 years ago

They don't need to specify an mc version, autoversion figures it out.

We cannot provide support for this problem, not all the code is even provided as you're require'ing out of files in the ./mineflayer folder. If you have a specific error message or a concise, mineflayer-only problem that we can provide support for. I recommend starting with a much simpler code base, echoing messages to the console, and then slowly adding the discord.js elements to see where this code went wrong.

builder-247 commented 3 years ago

They don't need to specify an mc version, autoversion figures it out.

We cannot provide support for this problem, not all the code is even provided as you're require'ing out of files in the ./mineflayer folder. If you have a specific error message or a concise, mineflayer-only problem that we can provide support for. I recommend starting with a much simpler code base, echoing messages to the console, and then slowly adding the discord.js elements to see where this code went wrong.

I don't think autoversion works on hypixel, at least according to my testing

nickelpro commented 3 years ago

Oh if it's behind a Velocity/Bungee proxy that's reporting an unsupported version ya, you'll need to specify a version. Good catch.

Tofaa2 commented 3 years ago

They don't need to specify an mc version, autoversion figures it out.

We cannot provide support for this problem, not all the code is even provided as you're require'ing out of files in the ./mineflayer folder. If you have a specific error message or a concise, mineflayer-only problem that we can provide support for. I recommend starting with a much simpler code base, echoing messages to the console, and then slowly adding the discord.js elements to see where this code went wrong.

That is all of it ;-; theres only message.js which i specified

Tofaa2 commented 3 years ago

Oh if it's behind a Velocity/Bungee proxy that's reporting an unsupported version ya, you'll need to specify a version. Good catch.

Tofaa2 commented 3 years ago

Thanks tons guys applying the version property fixed the issue :D