midjourney_client 0.3.0-dev.1 midjourney_client: ^0.3.0-dev.1 copied to clipboard
Unofficial midjourney client that gives you possibility to generates images! Now, it utilizes the Discord API to communicate with the bot.
Midjourney Client (Unofficial) #
This is an unofficial client for Midjourney that interfaces with the authentic Midjourney Bot via a Discord account token. As of now, it's stability has not been thoroughly tested. Consequently, it is advised against utilizing this client in production environments.
Table of Contents #
Install #
For a flutter project, consider running this command:
flutter pub add midjourney_client
For a dart project, consider running this command:
dart pub add midjourney_client
This installs the midjourney_client library and its dependencies.
Usage #
import 'dart:async';
import 'package:midjourney_client/midjourney_client.dart';
Future<void> main(List<Object> arguments) async {
final client = midjourney_client.Midjourney(
serverId: 'SERVER_ID',
channelId: 'CHANNEL_ID',
token: 'TOKEN',
loggerLevel: midjourney_client.MLoggerLevel.debug,
);
await client.init();
// client.imagine returns stream
final imagine = await client.imagine('Elephant on a tree').last;
// create variations
final variations = await client.variations(imagine, 1).last;
// upscale variations
final upscaled = client.upscale(variations, 1)..listen(print);
final uResult = await upscaled.last;
print(uResult);
}
Set up #
Pre-requisites:
How to get server id & channel id #
- Open Discord app
- Open your server
- Right click on the message inside the channel you want to use
- Copy link to message, this should look like
https://discord.com/channels/${SERVER_ID}/${CHANNEL_ID}/${MESSAGE_ID}
- Extract
SERVER_ID
andCHANNEL_ID
from the link
How to get token #
This one is a bit tricky, but here's how you can get it:
- Login to discord web app
- Open developer tools, head for Network tab
- Send a message to the channel you want to use or reload the page
- Click on a random request and go to request headers
- Find
Authorization
header and extract the value, it is your token
Examples #
This examples will instantiate a websocket connection to Discord Server and act as a Discord client sending messages to the channel specified by the CHANNEL_ID
environment variable. The SERVER_ID
environment variable is used to identify the server to which the channel belongs. The TOKEN
environment variable is used to authenticate the client.
Imagine #
This example will trigger /imagine
command on the Midjourney Bot and print the result.
dart run --define=SERVER_ID="" --define=CHANNEL_ID="" --define=TOKEN="" example/imagine.dart
import 'dart:async';
import 'dart:io';
import 'package:midjourney_client/midjourney_client.dart' as midjourney_client;
import 'env.dart';
Future<void> main(List<Object> arguments) async {
final client = midjourney_client.Midjourney(
serverId: Env.serverId,
channelId: Env.channelId,
token: Env.token,
loggerLevel: midjourney_client.MLoggerLevel.debug,
);
await client.init();
final imagine = client.imagine('Cat in a hat')..listen(print);
final result = await imagine.last;
print('Result: $result');
exit(0);
}
Variation #
This example will trigger /imagine
command on the Midjourney Bot, wait and trigger first variation.
dart run --define=SERVER_ID="" --define=CHANNEL_ID="" --define=TOKEN="" example/variations.dart
import 'dart:async';
import 'dart:io';
import 'package:midjourney_client/midjourney_client.dart' as midjourney_client;
import 'env.dart';
Future<void> main(List<Object> arguments) async {
final client = midjourney_client.Midjourney(
serverId: Env.serverId,
channelId: Env.channelId,
token: Env.token,
loggerLevel: midjourney_client.MLoggerLevel.debug,
);
await client.init();
final imagine = client.imagine('Cat with sword')..listen(print);
final result = await imagine.last;
final variation = client.variation(result, 1)..listen(print);
final vResult = await variation.last;
print(vResult);
exit(0);
}
Upscale #
This example will trigger /imagine
command on the Midjourney Bot, wait and trigger first upscale.
dart run --define=SERVER_ID="" --define=CHANNEL_ID="" --define=TOKEN="" example/upscale.dart
import 'dart:async';
import 'dart:io';
import 'package:midjourney_client/midjourney_client.dart' as midjourney_client;
import 'env.dart';
Future<void> main(List<Object> arguments) async {
final client = midjourney_client.Midjourney(
serverId: Env.serverId,
channelId: Env.channelId,
token: Env.token,
loggerLevel: midjourney_client.MLoggerLevel.verbose,
);
await client.init();
final imagine = client.imagine('Cat with a sword')..listen(print);
final result = await imagine.last;
final upscaled = client.upscale(result, 1)..listen(print);
final uResult = await upscaled.last;
print('Result: $uResult');
exit(0);
}