Skip to content

Latest commit

 

History

History
124 lines (102 loc) · 2.29 KB

README.md

File metadata and controls

124 lines (102 loc) · 2.29 KB

midjourney-sdk npm version

MidJourney in Discord API for Node.js.

It's useful for you, please give me open source power、support and star✨ this repo.

Demo

Live demo

Support

  • Command
    • /imagine
    • /info
    • /settings
    • /fast
    • /relax
  • Button Action
    • upscale
    • variation
    • reroll
    • zoomout
    • vary(Region)
  • Remix Mode

Install

pnpm i midjourney-sdk

Usage

import { MidJourney } from 'midjourney-sdk'
const ins = new MidJourney({
  token: process.env.NEXT_PUBLIC_TOKEN,
  guild_id: process.env.NEXT_PUBLIC_GUILD_ID,
  channel_id: process.env.NEXT_PUBLIC_CHANNEL_ID,
  skipHeartbeat: true
})
;(async () => {
  await ins.init()
  // trigger image job
  const msg1 = await ins.api.imagine('apple --q 5', ({ url, progress }) => {
    console(url, progress)
  })
  // trigger button job
  const msg2 = await ins.api.action(
    'msgId',
    'customId',
    'msgFlags',
    ({ url, progress }) => {
      console(url, progress)
    }
  )
  // trigger remix job
  const msg3 = await ins.api.remixSubmit(
    'modalMsgId',
    'customId',
    'components',
    ({ url, progress }) => {
      console(url, progress)
    }
  )
  // trigger vary(region) job
  const msg4 = await ins.api.varyRegion(
    'customId',
    'prompt',
    'mask',
    ({ url, progress }) => {
      console(url, progress)
    }
  )
})()

Development

  • edit environment .env file
# packages/playground-next/.env
NEXT_PUBLIC_TOKEN=
NEXT_PUBLIC_GUILD_ID=
NEXT_PUBLIC_CHANNEL_ID=
# discord api proxy url
NEXT_PUBLIC_API_BASE_URL=
# discord websocket proxy url
NEXT_PUBLIC_IMG_BASE_URL=
# discord websocket proxy url
NEXT_PUBLIC_WS_BASE_URL=
  • run dev script
pnpm dev
  • open http://localhost:3000

Proxy

  • edit environment .env file
# packages/proxy/.env
HTTP_PROXY=http://localhost:7890
PORT=9000
  • run dev script
pnpm proxy