Using proxies

Hi there! Im trying to make a Minecraft bot and i cant figure out how can i route its trafic through a proxy. This is my code:
import { createBot } from "npm:mineflayer";
import { handleLogin } from "./handlers/login.ts";
import { handleError } from "./handlers/error.ts";
import { handleSpawn } from "./handlers/spawn.ts";
import { handlePhysickTick } from "./handlers/physickTick.ts";

declare module "npm:mineflayer" {
interface BotOptions {
debug?: boolean;
}

interface Bot {
debug?: boolean;
state: number;
}
}

const env = Deno.env.toObject();

const bot = createBot({
host: env.HOST,
port: Number(env.PORT),
username: "..",
version: env.VERSION,
});

bot.debug = env.DEBUG === "true" || false;
bot.state = 0;

bot.on("error", (err) => handleError(err));
bot.on("login", () => handleLogin(bot));
bot.on("physicTick", () => handlePhysickTick());
bot.on("spawn", () => handleSpawn(bot));
import { createBot } from "npm:mineflayer";
import { handleLogin } from "./handlers/login.ts";
import { handleError } from "./handlers/error.ts";
import { handleSpawn } from "./handlers/spawn.ts";
import { handlePhysickTick } from "./handlers/physickTick.ts";

declare module "npm:mineflayer" {
interface BotOptions {
debug?: boolean;
}

interface Bot {
debug?: boolean;
state: number;
}
}

const env = Deno.env.toObject();

const bot = createBot({
host: env.HOST,
port: Number(env.PORT),
username: "..",
version: env.VERSION,
});

bot.debug = env.DEBUG === "true" || false;
bot.state = 0;

bot.on("error", (err) => handleError(err));
bot.on("login", () => handleLogin(bot));
bot.on("physicTick", () => handlePhysickTick());
bot.on("spawn", () => handleSpawn(bot));
2 Replies
Leokuma
Leokuma3w ago
Since you're using Node packages, you'll have to try using an environment variable, although I'm not sure if it covers Node packages There's HTTP_PROXY and HTTPS_PROXY. Take a look here: https://docs.deno.com/runtime/reference/env_variables/#special-environment-variables If you were using only Deno packages, you could alternatively set the proxy in Deno.createHttpClient
Deno
Environment variables
A guide to working with environment variables in Deno. Learn about Deno.env API, .env file support, CLI configuration, and special environment variables that control Deno's behavior.
Leokuma
Leokuma3w ago
If that doesn't work, I think you'll have to configure the proxy at OS level

Did you find this page helpful?