npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mj-reforged

v1.1.3

Published

Midjourney client using Discord. Forked from UrielCh's project.

Downloads

7

Readme

mj-reforged

Deno doc

midjourney-discord-api is a library designed to connect to a Discord channel and send messages to be processed by the Midjourney bot. It utilizes the same requests as the Discord web client, allowing seamless communication with the bot. To configure the library, extract an authenticated request sent to the Midjourney bot using your web development tools.

Contributor notice: MJ Reforged is the version of the real package but with crucial fixes and modifications for custom needs.

The real package was created by UrielCh

This project is not affiliated with the real package.

Features

| feature | Status | feature | Status | | ----------- | ------ | ------------ | ------ | | /blend | ✅ | Reroll | ✅ | | /describe | ✅ | /relax | ✅ | | /fast | ✅ | /settings | ✅ | | /imagine | ✅ | Variations | ✅ | | Upscale | ✅ | concurent calls| ✅ | | /private | ❌ N/A | /public | ❌ N/A | | /show | ❌ N/A |/stealth | ❌ N/A |

Installation

NodeJS ESM or CJS

npm install mj-reforged

ESM nodeJS

import Midjourney from "mj-reforged";

const cli = new Midjourney("interaction.txt");
const msgs = await cli.getMessages();
console.log(msgs.length + " messages visibles"); // by default get 50 messages

Token / ids extraction.

  • Open your webbrowser
  • Go to your discord channel
  • Open the developent bar
  • Go to network
  • Send a request to discordBot, like /settings
  • Left click on the https://discord.com/api/v9/interactions request.
  • Click Copy
  • Click Copy as fetch
  • Save this request in a file, that you will provide to the Midjourney constructor. (for my Test I name this file interaction.txt)

Midjourney client initializartion

the Midjourney client can be initilized in 4 different ways:

new Midjourney(filename) fetch command

in this case the provided file should contains a valid NodeJS fetch command as described in the previous section.

filename can also be replace by it's content.

new Midjourney(filename) environement file

in this case the provided file should contains somthink like:

SALAI_TOKEN = your 72 char long authorization token
SERVER_ID = the serverId
CHANNEL_ID = the channelId

SERVER_ID and CHANNEL_ID can be omit, if you provide those data using Midjourney.setDiscordChannelUrl("https://discord.com/channels/1234567890/1234567890")

environement variable

in this case SALAI_TOKEN should contains you 72 char long authorization token. SERVER_ID and CHANNEL_ID should contains the serverId and channelId

SERVER_ID and CHANNEL_ID can be omit, if you provide those data using Midjourney.setDiscordChannelUrl("https://discord.com/channels/1234567890/1234567890")

new Midjourney(SALAI_TOKEN) directly provide SALAI_TOKEN

in this case a 72 char long SALAI_TOKEN token should be pass to the Midjourney constructor like: new Midjourney(SALAI_TOKEN)

then you will have to provide serverId and channelId using Midjourney.setDiscordChannelUrl("https://discord.com/channels/1234567890/1234567890")

Usage

Here are some examples of how to use the Midjourney class:

Describe URL

import Midjourney from "midjourney-discord-api";

const client = new Midjourney("interaction.txt");
await client.connectWs(); // Used Websocket to boost detection. (experiental)
const prompts: string[] = await client.describeUrl(
  "https://cdn.midjourney.com/95e2c8fd-255c-4982-9065-83051143570c/0_0_640_N.webp",
  /* add optional progress function (percent) => void*/
);
console.log("reversed prompt: ", prompts);

Imagine

import Midjourney from "midjourney-discord-api";

const client = new Midjourney("interaction.txt");
await client.connectWs(); // Used Websocket to boost detection. (experiental)
const msg = await client.imagine(
  "A photo of an astronaut riding a horse", 
  /* add optional progress function (percent) => void */
);
console.log("you find your result here: ", msg.attachments[0].url);

Upscale

/**
 * Upscale the first none upscaled images in chat, searching from the newest to the oldest images
 */
import Midjourney from "midjourney-discord-api";

/**
 * Variant the last image available in chat
 */
const client = new Midjourney("interaction.txt");
await client.connectWs(); // Used Websocket to boost detection. (experiental)
const msgs = await client.getMessages();
main:
for (const msg of msgs) {
  if (!msg.canVariant()) {
    continue;
  }
  for (let i = 1; i <= 4; i++) {
    const v = msg.canVariant(i)
    if (v) {
      console.log(`Variant image ${v.custom_id} from ${msg.id}: ${msg.prompt?.prompt}`);
      const result = await msg.variant(i /* , add optional progress function (percent) => void */);
      await result.download(0, "images");
      break main;
    }
  }
}

Variant

/**
 * Variant the last image available in chat
 */
const client = new Midjourney("interaction.txt");
await client.connectWs(); // Used Websocket to boost detection. (experiental)
const msgs = await client.getMessages();
main:
for (const msg of msgs) {
  if (!msg.canVariant()) {
    continue;
  }
  for (let i = 1; i <= 4; i++) {
    const v = msg.canVariant(i)
    if (v) {
      console.log(`Variant image ${v.custom_id} from ${msg.id}: ${msg.prompt?.prompt}`);
      const result = await msg.variant(i/* , add optional progress function (percent) => void */);
      await result.download(0, "images");
      break main;
    }
  }
}

Reroll

import Midjourney from "midjourney-discord-api";

const client = new Midjourney("interaction.txt");
await client.connectWs(); // Used Websocket to boost detection. (experiental)
const msg = await client.imagine(
  "A photo of an astronaut riding a horse",
  /* add optional progress function (percent) => void */
);
if (msg.canReroll()) {
  const result = msg.reroll(/* add optional progress function (percent) => void */);
  console.log(`upscale V2 Ready from`, result.attachments[0].url);
}

More Samples

check all the samples here

Contributing

We welcome contributions to the midjourney-discord-api project. Please feel free to submit issues, feature requests, and pull requests to improve the project.

reference

License

This project is licensed under the MIT License.