├── Globals.py
├── LICENSE.md
├── README.md
├── Salai.py
├── main.py
└── requirements.txt
/Globals.py:
--------------------------------------------------------------------------------
1 | #strings
2 |
3 | DAVINCI_TOKEN = [Token of Discord bot]
4 |
5 | SERVER_ID = [Server id here]
6 |
7 | SALAI_TOKEN = [Token of the Account from which you paid MidJourney ]
8 |
9 | CHANNEL_ID = [Channel in which commands are sent]
10 |
11 | #boolean
12 | USE_MESSAGED_CHANNEL = False
13 |
14 | #don't edit the following variable
15 | MID_JOURNEY_ID = "936929561302675456" #midjourney bot id
16 | targetID = ""
17 | targetHash = ""
18 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Creative Commons Legal Code
2 |
3 | CC0 1.0 Universal
4 |
5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12 | HEREUNDER.
13 |
14 | Statement of Purpose
15 |
16 | The laws of most jurisdictions throughout the world automatically confer
17 | exclusive Copyright and Related Rights (defined below) upon the creator
18 | and subsequent owner(s) (each and all, an "owner") of an original work of
19 | authorship and/or a database (each, a "Work").
20 |
21 | Certain owners wish to permanently relinquish those rights to a Work for
22 | the purpose of contributing to a commons of creative, cultural and
23 | scientific works ("Commons") that the public can reliably and without fear
24 | of later claims of infringement build upon, modify, incorporate in other
25 | works, reuse and redistribute as freely as possible in any form whatsoever
26 | and for any purposes, including without limitation commercial purposes.
27 | These owners may contribute to the Commons to promote the ideal of a free
28 | culture and the further production of creative, cultural and scientific
29 | works, or to gain reputation or greater distribution for their Work in
30 | part through the use and efforts of others.
31 |
32 | For these and/or other purposes and motivations, and without any
33 | expectation of additional consideration or compensation, the person
34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35 | is an owner of Copyright and Related Rights in the Work, voluntarily
36 | elects to apply CC0 to the Work and publicly distribute the Work under its
37 | terms, with knowledge of his or her Copyright and Related Rights in the
38 | Work and the meaning and intended legal effect of CC0 on those rights.
39 |
40 | 1. Copyright and Related Rights. A Work made available under CC0 may be
41 | protected by copyright and related or neighboring rights ("Copyright and
42 | Related Rights"). Copyright and Related Rights include, but are not
43 | limited to, the following:
44 |
45 | i. the right to reproduce, adapt, distribute, perform, display,
46 | communicate, and translate a Work;
47 | ii. moral rights retained by the original author(s) and/or performer(s);
48 | iii. publicity and privacy rights pertaining to a person's image or
49 | likeness depicted in a Work;
50 | iv. rights protecting against unfair competition in regards to a Work,
51 | subject to the limitations in paragraph 4(a), below;
52 | v. rights protecting the extraction, dissemination, use and reuse of data
53 | in a Work;
54 | vi. database rights (such as those arising under Directive 96/9/EC of the
55 | European Parliament and of the Council of 11 March 1996 on the legal
56 | protection of databases, and under any national implementation
57 | thereof, including any amended or successor version of such
58 | directive); and
59 | vii. other similar, equivalent or corresponding rights throughout the
60 | world based on applicable law or treaty, and any national
61 | implementations thereof.
62 |
63 | 2. Waiver. To the greatest extent permitted by, but not in contravention
64 | of, applicable law, Affirmer hereby overtly, fully, permanently,
65 | irrevocably and unconditionally waives, abandons, and surrenders all of
66 | Affirmer's Copyright and Related Rights and associated claims and causes
67 | of action, whether now known or unknown (including existing as well as
68 | future claims and causes of action), in the Work (i) in all territories
69 | worldwide, (ii) for the maximum duration provided by applicable law or
70 | treaty (including future time extensions), (iii) in any current or future
71 | medium and for any number of copies, and (iv) for any purpose whatsoever,
72 | including without limitation commercial, advertising or promotional
73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74 | member of the public at large and to the detriment of Affirmer's heirs and
75 | successors, fully intending that such Waiver shall not be subject to
76 | revocation, rescission, cancellation, termination, or any other legal or
77 | equitable action to disrupt the quiet enjoyment of the Work by the public
78 | as contemplated by Affirmer's express Statement of Purpose.
79 |
80 | 3. Public License Fallback. Should any part of the Waiver for any reason
81 | be judged legally invalid or ineffective under applicable law, then the
82 | Waiver shall be preserved to the maximum extent permitted taking into
83 | account Affirmer's express Statement of Purpose. In addition, to the
84 | extent the Waiver is so judged Affirmer hereby grants to each affected
85 | person a royalty-free, non transferable, non sublicensable, non exclusive,
86 | irrevocable and unconditional license to exercise Affirmer's Copyright and
87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the
88 | maximum duration provided by applicable law or treaty (including future
89 | time extensions), (iii) in any current or future medium and for any number
90 | of copies, and (iv) for any purpose whatsoever, including without
91 | limitation commercial, advertising or promotional purposes (the
92 | "License"). The License shall be deemed effective as of the date CC0 was
93 | applied by Affirmer to the Work. Should any part of the License for any
94 | reason be judged legally invalid or ineffective under applicable law, such
95 | partial invalidity or ineffectiveness shall not invalidate the remainder
96 | of the License, and in such case Affirmer hereby affirms that he or she
97 | will not (i) exercise any of his or her remaining Copyright and Related
98 | Rights in the Work or (ii) assert any associated claims and causes of
99 | action with respect to the Work, in either case contrary to Affirmer's
100 | express Statement of Purpose.
101 |
102 | 4. Limitations and Disclaimers.
103 |
104 | a. No trademark or patent rights held by Affirmer are waived, abandoned,
105 | surrendered, licensed or otherwise affected by this document.
106 | b. Affirmer offers the Work as-is and makes no representations or
107 | warranties of any kind concerning the Work, express, implied,
108 | statutory or otherwise, including without limitation warranties of
109 | title, merchantability, fitness for a particular purpose, non
110 | infringement, or the absence of latent or other defects, accuracy, or
111 | the present or absence of errors, whether or not discoverable, all to
112 | the greatest extent permissible under applicable law.
113 | c. Affirmer disclaims responsibility for clearing rights of other persons
114 | that may apply to the Work or any use thereof, including without
115 | limitation any person's Copyright and Related Rights in the Work.
116 | Further, Affirmer disclaims responsibility for obtaining any necessary
117 | consents, permissions or other rights required for any use of the
118 | Work.
119 | d. Affirmer understands and acknowledges that Creative Commons is not a
120 | party to this document and has no duty or obligation with respect to
121 | this CC0 or use of the Work.
122 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WARNING
2 | DUE TO LACK OF TIME AND MULTIPLE API'S UPDATES, THIS REPOSITORY IS NOT UP TO DATE, AND MAY BE DEPRICATED. I MAY CONSIDER COMING BACK TO THIS PROJECT LATER...
3 | # MidJourney-Wrapper
4 |
5 | ## Presentation
6 | The point of this bot is using [MidJouney](https://www.midjourney.com/home/) from an account other than the account you paid from.
7 | To do so, there should be a Discord bot, which we will call DaVinci (see [Globals](https://github.com/Wildric-Auric/MidJourney-Wrapper/blob/main/Globals.py)), and the account subscribed to MidJourney, which we will call Salai, in the same server. Any discord user in the server can use DaVinci commands to generate images, their variations, upscale them...
8 | Warning though; you aren't allowed to use this software in the purpose of sharing your subscription with other people; this software is intended to be used only for learning purposes. If you infringe the rules, please know that you are solely responsible.
9 |
10 | ## Installation
11 | * Clone the project.
12 | * Install [requirements](https://github.com/Wildric-Auric/MidJourney-Wrapper/blob/main/requirements.txt) (only pycord version 2) and discord python api module if needed.
13 | * Fill [Globals.py](https://github.com/Wildric-Auric/MidJourney-Wrapper/blob/main/Globals.py) with your data
14 | * Run main.py;
15 |
16 | ## Implemented commands documentation
17 | *MT stands for mandatory*
18 | *OPT stands for optional*
19 | ### Generating idea
20 | ```
21 | /mj_imagine [ MT : prompt (string)]
22 | ```
23 |
24 |
25 | 
26 |
27 |
28 | ### Targetting image
29 | Reply to MidJourney Bot message by the following command to target that piece of art for the next operation:
30 | ```
31 | $mj_target
32 | ```
33 | Notice that slash command is not used here because of discord not allowing Interactions during reply. Hence, there is no autocomplete, your reply is simply parsed to get the command.
34 |
35 |
36 | 
37 |
38 |
39 | ### Upscaling and variations
40 | ```
41 | /mj_upscale [ MT : index (integer) ] [ OPT : reset_target (boolean) ]
42 | ```
43 | *index* parameter takes values from 1 to 4; 1 is the index of top left image and 4 is the index of buttom right one.
44 | The optional parameter *reset_target* indicates if target you have set before should be reset at the end of current operation; if that's done and you want to upscale image from same message with different index you should use *$mj_target* command again.
45 |
46 |
47 | 
48 |
49 |
50 | Generated image:
51 |
52 | 
53 |
54 | Notice that we cannot use ```/mj_upscale_to_max``` on this output since we used *--hd* parameter which makes a sigle upscale maximized.
55 | This last command does not require a parameter and it resets target since no other operation is possible on this output other than upscaling to max. But remember that you need again to target what you need to upscale for the second time.
56 |
57 | There is another command that uses the output of ```/mj_imagine```:
58 | ```
59 | /mj_upscale_to_max [ MT : index (integer) ] [ OPT : reset_target (boolean) ]
60 | ```
61 | It behaves the same way as upscaling command.
62 |
63 | ## Additional information
64 | Even though a request error is caught by the bot (a problem with MidJourney bot, a problem with the subscripted account...) since it shows up as HTTP request error, it does not caught errors done by the user; for example if there was a typo using MidJourney parameters like ```-hd``` instead of ```--hd``` MidJourney reports it to the subscripted user but DaVinci does not complain about it, so pay attention to your inputs. Also read the official user [documentation](https://midjourney.gitbook.io/docs/user-manual) of MidJourney.
65 |
66 | *Enjoy!*
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/Salai.py:
--------------------------------------------------------------------------------
1 | import Globals
2 | import requests
3 |
4 | def PassPromptToSelfBot(prompt : str):
5 | payload ={"type":2,"application_id":"936929561302675456","guild_id":Globals.SERVER_ID,
6 | "channel_id":Globals.CHANNEL_ID,"session_id":"2fb980f65e5c9a77c96ca01f2c242cf6",
7 | "data":{"version":"1077969938624553050","id":"938956540159881230","name":"imagine","type":1,"options":[{"type":3,"name":"prompt","value":prompt}],
8 | "application_command":{"id":"938956540159881230",
9 | "application_id":"936929561302675456",
10 | "version":"1077969938624553050",
11 | "default_permission":True,
12 | "default_member_permissions":None,
13 | "type":1,"nsfw":False,"name":"imagine","description":"Create images with Midjourney",
14 | "dm_permission":True,
15 | "options":[{"type":3,"name":"prompt","description":"The prompt to imagine","required":True}]},
16 | "attachments":[]}}
17 |
18 |
19 | header = {
20 | 'authorization' : Globals.SALAI_TOKEN
21 | }
22 | response = requests.post("https://discord.com/api/v9/interactions",
23 | json = payload, headers = header)
24 | return response
25 |
26 | def Upscale(index : int, messageId : str, messageHash : str):
27 | payload = {"type":3,
28 | "guild_id":Globals.SERVER_ID,
29 | "channel_id":Globals.CHANNEL_ID,
30 | "message_flags":0,
31 | "message_id": messageId,
32 | "application_id":"936929561302675456",
33 | "session_id":"45bc04dd4da37141a5f73dfbfaf5bdcf",
34 | "data":{"component_type":2,
35 | "custom_id":"MJ::JOB::upsample::{}::{}".format(index, messageHash)}
36 | }
37 | header = {
38 | 'authorization' : Globals.SALAI_TOKEN
39 | }
40 | response = requests.post("https://discord.com/api/v9/interactions",
41 | json = payload, headers = header)
42 | return response
43 |
44 |
45 |
46 |
47 | def MaxUpscale(messageId : str, messageHash : str):
48 | payload = {"type":3,
49 | "guild_id":Globals.SERVER_ID,
50 | "channel_id":Globals.CHANNEL_ID,
51 | "message_flags":0,
52 | "message_id": messageId,
53 | "application_id":"936929561302675456",
54 | "session_id":"1f3dbdf09efdf93d81a3a6420882c92c","data":
55 | {"component_type":2,"custom_id":"MJ::JOB::upsample_max::1::{}::SOLO".format(messageHash)}}
56 | header = {
57 | 'authorization' : Globals.SALAI_TOKEN
58 | }
59 | response = requests.post("https://discord.com/api/v9/interactions",
60 | json = payload, headers = header)
61 | return response
62 |
63 |
64 | def Variation(index : int,messageId : str, messageHash : str):
65 | payload = {"type":3, "guild_id":Globals.SERVER_ID,
66 | "channel_id": Globals.CHANNEL_ID,
67 | "message_flags":0,
68 | "message_id": messageId,
69 | "application_id": "936929561302675456",
70 | "session_id":"1f3dbdf09efdf93d81a3a6420882c92c",
71 | "data":{"component_type":2,"custom_id":"MJ::JOB::variation::{}::{}".format(index, messageHash)}}
72 | header = {
73 | 'authorization' : Globals.SALAI_TOKEN
74 | }
75 | response = requests.post("https://discord.com/api/v9/interactions",
76 | json = payload, headers = header)
77 | return response
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | import discord
2 | import Globals
3 | from Salai import PassPromptToSelfBot, Upscale, MaxUpscale, Variation
4 |
5 | bot = discord.Bot(intents=discord.Intents.all())
6 |
7 |
8 | @bot.event
9 | async def on_ready():
10 | print(f"Logged in as {bot.user}")
11 |
12 |
13 | @bot.command(description="Make DaVinci say something")
14 | async def hello(ctx, sentence: discord.Option(str)):
15 | await ctx.respond(sentence)
16 |
17 |
18 | @bot.command(description="This command is a wrapper of MidJourneyAI")
19 | async def mj_imagine(ctx, prompt: discord.Option(str)):
20 |
21 | if (Globals.USE_MESSAGED_CHANNEL):
22 | Globals.CHANNEL_ID = ctx.channel.id
23 |
24 | response = PassPromptToSelfBot(prompt)
25 |
26 | if response.status_code >= 400:
27 | print(response.text)
28 | print(response.status_code)
29 | await ctx.respond("Request has failed; please try later")
30 | else:
31 | await ctx.respond(
32 | "Your image is being prepared, please wait a moment...")
33 |
34 |
35 | @bot.command(description="Upscale one of images generated by MidJourney")
36 | async def mj_upscale(ctx, index: discord.Option(int), reset_target : discord.Option(bool) =True):
37 | if (index <= 0 or index > 4):
38 | await ctx.respond("Invalid argument, pick from 1 to 4")
39 | return
40 |
41 | if Globals.targetID == "":
42 | await ctx.respond(
43 | 'You did not set target. To do so reply to targeted message with "$mj_target"'
44 | )
45 | return
46 |
47 | if (Globals.USE_MESSAGED_CHANNEL):
48 | Globals.CHANNEL_ID = ctx.channel.id
49 | response = Upscale(index, Globals.targetID, Globals.targetHash)
50 | if reset_target:
51 | Globals.targetID = ""
52 | if response.status_code >= 400:
53 | await ctx.respond("Request has failed; please try later")
54 | return
55 |
56 | await ctx.respond("Your image is being prepared, please wait a moment...")
57 |
58 | @bot.command(description="Upscale to max targetted image (should be already upscaled using mj_upscale)")
59 | async def mj_upscale_to_max(ctx):
60 | if Globals.targetID == "":
61 | await ctx.respond(
62 | 'You did not set target. To do so reply to targeted message with "$mj_target"'
63 | )
64 | return
65 |
66 | if (Globals.USE_MESSAGED_CHANNEL):
67 | Globals.CHANNEL_ID = ctx.channel.id
68 |
69 | response = MaxUpscale(Globals.targetID, Globals.targetHash)
70 | Globals.targetID = ""
71 | if response.status_code >= 400:
72 | await ctx.respond("Request has failed; please try later")
73 | return
74 |
75 | await ctx.respond("Your image is being prepared, please wait a moment...")
76 |
77 | @bot.command(description = "Make variation given index after target has been set")
78 | async def mj_variation(ctx, index: discord.Option(int), reset_target : discord.Option(bool) =True):
79 | if (index <= 0 or index > 4):
80 | await ctx.respond("Invalid argument, pick from 1 to 4")
81 | return
82 |
83 | if Globals.targetID == "":
84 | await ctx.respond(
85 | 'You did not set target. To do so reply to targeted message with "$mj_target"'
86 | )
87 | return
88 |
89 |
90 | if (Globals.USE_MESSAGED_CHANNEL):
91 | Globals.CHANNEL_ID = ctx.channel.id
92 |
93 | response = Variation(index, Globals.targetID, Globals.targetHash)
94 | if reset_target:
95 | Globals.targetID = ""
96 | if response.status_code >= 400:
97 | await ctx.respond("Request has failed; please try later")
98 | return
99 |
100 | await ctx.respond("Your image is being prepared, please wait a moment...")
101 |
102 |
103 |
104 | @bot.event
105 | async def on_message(message):
106 | if message.content == "": return
107 | if "$mj_target" in message.content and message.content[0] == '$':
108 | try:
109 | Globals.targetID = str(message.reference.message_id)
110 | #Get the hash from the url
111 | Globals.targetHash = str((message.reference.resolved.attachments[0].url.split("_")[-1]).split(".")[0])
112 | except:
113 | await message.channel.send(
114 | "Exception has occured, maybe you didn't reply to MidJourney message"
115 | )
116 | await message.delete()
117 | return
118 | if str(message.reference.resolved.author.id) != Globals.MID_JOURNEY_ID:
119 | await message.channel.send(
120 | "Use the command only when you reply to MidJourney")
121 | await message.delete()
122 | return
123 | await message.channel.send("Done")
124 | await message.delete()
125 |
126 |
127 | bot.run(Globals.DAVINCI_TOKEN)
128 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | py-cord==2.0.0b1
2 |
--------------------------------------------------------------------------------