erictik / midjourney-api

MidJourney client. Unofficial Node.js client
Apache License 2.0
1.65k stars 271 forks source link

error 400 when testing command #122

Open NotReks opened 1 year ago

NotReks commented 1 year ago

here's the code


const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
const axios = require('axios')
const { Midjourney } = require('midjourney');

const midjourneyClient = new Midjourney({
    ServerId: '1118903793686425631', 
    ChannelId: '1118903794374283296', 
    SalaiToken: '/// cant send that', 
    Debug: true,
    Ws: true,
});

client.once('ready', () => {
    console.log('bot is rdy')
})

client.on('messageCreate', async message => {
    if (message.content.startsWith('!imagine')) {
      console.log('Command received!'); // Debug log
      console.log(`Received message: ${message.content}`);
      const prompt = message.content.slice('!imagine '.length);

      try {
        console.log('Sending bot is thinking... message'); // Debug log
        const botMessage = await message.reply('Bot is cooking...');

        console.log('Making API request'); // Debug log

        const Imagine = await midjourneyClient.Imagine(prompt, (uri, progress) => {
          console.log("Imagine URI:", uri, "Progress:", progress);
        });

        console.log({ Imagine });

        console.log('Editing message with image'); // Debug log
        await botMessage.edit(`Here's your image for the prompt "${prompt}"`);
        await message.channel.send(Imagine.content); 

      } catch (error) {
        console.error(`Error encountered: ${error.message}`); // Debug log
      }
    }
  });

client.login('/// cant send that')```

here's the error:

Imagine [3195733217] anime girl nonce 1118907296554942464 2023-06-15T14:18:07.791Z
api.DiscordBaseUrl https://discord.com/
api.fetchUrl https://discord.com/api/v9/interactions
Error encountered: ImagineApi failed with status 400
api.error.config {
  payload: {
    type: 2,
    application_id: '936929561302675456',
    guild_id: '1118903793686425631',
    channel_id: '1118903794374283296',
    session_id: '8bb7f5b79c7a49f7d0824ab4b8773a81',
    data: {
      version: '1077969938624553050',
      id: '938956540159881230',
      name: 'imagine',
      type: 1,
      options: [Array],
      application_command: [Object],
      attachments: []
    },
    nonce: '1118907296554942464'
  },
  config: {
    ChannelId: '1118903794374283296',
    SalaiToken: '/// cant send that',
    SessionId: '8bb7f5b79c7a49f7d0824ab4b8773a81',
    Debug: true,
    Limit: 50,
    MaxWait: 200,
    DiscordBaseUrl: 'https://discord.com/',
    WsBaseUrl: 'wss://[gateway.discord.gg?v=9&encoding=json&compress=gzip-stream](http://gateway.discord.gg/?v=9&encoding=json&compress=gzip-stream)',
    ServerId: '1118903793686425631',
    Ws: true
  }
}
zcpua commented 1 year ago

check your SalaiToken u can join my discord server https://discord.com/invite/GavuGHQbV4 export SERVER_ID="1082500871478329374" export CHANNEL_ID="1094892992281718894"

zcpua commented 1 year ago

https://github.com/erictik/midjourney-api/blob/main/example/imagine-ws.ts run test

NotReks commented 1 year ago

Ok once I'm back home I'll join your discord, however I got my Salai token from the same location that it says in the documentation, however library had a region tag on it, but otherwise it was identical to the method seen in the doc

zcpua commented 1 year ago

Invite Midjourney Bot to Your Server

NotReks commented 1 year ago

Does midjourney need to be in? If so what's the point, I'll just use midjourney

zcpua commented 1 year ago

https://github.com/erictik/midjourney-ui u can share to non-subscribers or create webui

NotReks commented 1 year ago

It works now that midjourney is in, but all it does is send the command to that bot, I don't want midjourney to be present

jakowenko commented 1 year ago

It works now that midjourney is in, but all it does is send the command to that bot, I don't want midjourney to be present

What are you trying to do? The point of this package is to programmatically talk to Discord and the Midjourney Bot so you can pass prompts and download the images with just code.

NotReks commented 1 year ago

dont worry about it i figured it out, image thanks for your help

NotReks commented 1 year ago

it randomly broke, it was just working like 5 minutes ago ..? can someone add me on discord @reksarts so i can discuss this further and in better detail

jakowenko commented 1 year ago

I'm getting the error now too. Wonder if it's related to this message Midjourney posted in their Discord.

2023-06-15 at 14 17 55

NotReks commented 1 year ago

ok yeah i got that too

NotReks commented 1 year ago

You still getting the error?

jakowenko commented 1 year ago

Yes, a new version will need to be published with the updated prompt version ids. I made a ticket here to track it: https://github.com/erictik/midjourney-api/issues/124

crazyramirez commented 1 year ago

I´m getting the error also

NotReks commented 1 year ago

Is there no way to temporarily Atleast fix just the imagine?

crazyramirez commented 1 year ago

Error Finished Error: ImagineApi failed with status 400 at Midjourney.Imagine (C:***\src\midjourney.js:46:19) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

jakowenko commented 1 year ago

Is there no way to temporarily Atleast fix just the imagine?

You can fix it locally and build the package. There's only 10 lines that need to be updated for everything. But to build the remote package the owner needs to merge in the change.

NotReks commented 1 year ago

Yeah same, since the id shit updated I was hoping if there's a way to just go into the node_modules and adjust what would be required to get the imagine working Atleast

NotReks commented 1 year ago

Oh ok it's that much work? I'm good then lmfao I'll wait

jakowenko commented 1 year ago

Yeah same, since the id shit updated I was hoping if there's a way to just go into the node_modules and adjust what would be required to get the imagine working Atleast

If you want to try this you can. I think the /info one will need to be updated as well before the /imagine call happens.

/info: search for 987795925764280356 and update to 972289487818334209 /imagine: search for 1077969938624553050 and update to 1118961510123847772

crazyramirez commented 1 year ago

Yeah same, since the id shit updated I was hoping if there's a way to just go into the node_modules and adjust what would be required to get the imagine working Atleast

If you want to try this you can. I think the /info one will need to be updated as well before the /imagine call happens.

/info: search for 987795925764280356 and update to 972289487818334209 /imagine: search for 1077969938624553050 and update to 1118961510123847772

WORKING!!!! Thanks sir!! You´ve saved me hours of searching

NotReks commented 1 year ago

thank you dude

NotReks commented 1 year ago

does anything else need changed? I want to add functionality for variations and upscaling but I'm not sure if this new update broke them too

jakowenko commented 1 year ago

does anything else need changed? I want to add functionality for variations and upscaling but I'm not sure if this new update broke them too

Yes, those have different IDs. Probably best just to wait until the new version is patched. I'm guessing it'll be available later today.

crazyramirez commented 1 year ago

now for some strange reason it is duplicating the request to Midjourney

iamkunal9 commented 1 year ago

now for some strange reason it is duplicating the request to Midjourney

Working fine for me till now can you please elaborate the issue you are facing

NotReks commented 1 year ago

does anyone know what needs to be inputted for the prompt so that it replicates the result of nijijourney? theres some discrepancies when just using --niji 5

crazyramirez commented 1 year ago

Working again! The duplicated was a logic problem in my code (solved)

NotReks commented 1 year ago

Sometimes midjourney asks for an appeal, and when I appeal it my bot no longer sends progress updates only the finished one, can someone help me sort it?

stricklandye commented 1 year ago

I'm getting the error now too. Wonder if it's related to this message Midjourney posted in their Discord.

2023-06-15 at 14 17 55

@jakowenko Could you please tell which channel you saw this messge? If MidJourney publishes new version next time I can update the value ASAP.

jakowenko commented 1 year ago

I'm getting the error now too. Wonder if it's related to this message Midjourney posted in their Discord. 2023-06-15 at 14 17 55

@jakowenko Could you please tell which channel you saw this messge? If MidJourney publishes new version next time I can update the value ASAP.

It was in their status channel

2023-06-16 at 02 23 59

stricklandye commented 1 year ago

I'm getting the error now too. Wonder if it's related to this message Midjourney posted in their Discord. 2023-06-15 at 14 17 55

@jakowenko Could you please tell which channel you saw this messge? If MidJourney publishes new version next time I can update the value ASAP.

It was in their status channel

2023-06-16 at 02 23 59

I see, thanks.

NotReks commented 1 year ago

can one of you guys help me out? my bot doesnt pick up the progress pictures most of the time, and crashes after trying to do more than one variation, i can send the code if u would add me on discord @reksarts

crazyramirez commented 1 year ago

@NotReks What method are you using to receive the progress? Are you receiving the progress printed in your server log? Did you change to the new id values posted here?

Also maybe try using Socket.io and emit your progress to your client

NotReks commented 1 year ago

idk how discordjs works or any of this im just stringing together how I know stuff works in js and the documentation, please let me know what im doing wrong, and yes I updated the package through npm


const { Client, GatewayIntentBits, Attachment, Embed, ActionRow, ButtonComponent, ButtonStyle, ActionRowBuilder, ButtonBuilder } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
const axios = require('axios')
const { Midjourney } = require('midjourney');

const midjourneyClient = new Midjourney({
    ServerId: '1118903793686425631', 
    ChannelId: '1118903794374283296', 
    SalaiToken: '', 
    Debug: true,
    Ws: true,
});

let nijiSetting = '';

client.once('ready', () => {
    console.log('bot is rdy')

    client.user.setActivity('use !imagine to generate images')
})

client.on('messageCreate', async message => {
    if (message.content.startsWith('!settings')) {
      let setting = message.content.slice('!settings '.length);

      if (setting === 'niji1') {
        nijiSetting = ' --niji 5';
        await message.reply('Settings updated to niji1.');
      } else if (setting === 'niji2') {
        nijiSetting = '';
        await message.reply('Settings updated to niji2.');
      } else if (setting === 'nijiScenic') {
        nijiSetting = ' --niji 5 --style scenic';
        await message.reply('Settings updated to nijiScenic.');
      } else if (setting === 'nijiExpressive') {
        nijiSetting = ' --niji 5 --style expressive';
        await message.reply('Settings updated to nijiExpressive.');
      } else if (setting === 'nijiOriginal') {
        nijiSetting = ' --niji 5 --style original';
        await message.reply('Settings updated to nijiOriginal.');
      } else if (setting === 'nijiCute') {
        nijiSetting = ' --niji 5 --style cute';
        await message.reply('Settings updated to nijiCute.');
      } else {
        await message.reply('pick either `niji1`, `nijiExpressive`, `nijiScenic`, `nijiOriginal`, `nijiCute`, or `niji2`.');;
      }

    } else if (message.content.startsWith('!imagine')) {
      console.log('Command received!'); // Debug log
      console.log(`Received message: ${message.content}`);

      const prompt = message.content.slice('!imagine '.length);
      const finalPrompt = prompt + nijiSetting;

      try {
        console.log('Sending bot is thinking... message'); // Debug log
        const botMessage = await message.reply('Chef is cooking... (Waiting to start)');
        console.log('Making API request'); // Debug log

        const Imagine = await midjourneyClient.Imagine(finalPrompt, async (uri, progress) => {
          console.log("Imagine URI:", uri, "Progress:", progress);
          if (uri.endsWith('.webp')) {
            await botMessage.edit(`Bot is cooking... \nCurrent progress: ${progress} \nURL: ${uri}`);
          }
        });

        console.log({ Imagine });
        console.log('Editing message with image'); // Debug log
        await botMessage.edit(`Here's your image for the prompt "${prompt}"`);

        const variation1 = new ButtonBuilder()
            .setCustomId('variation1')
            .setLabel('V1')
            .setStyle(ButtonStyle.Primary);

        const variation2 = new ButtonBuilder()
            .setCustomId('variation2')
            .setLabel('V2')
            .setStyle(ButtonStyle.Primary);

        const variation3 = new ButtonBuilder()
            .setCustomId('variation3')
            .setLabel('V3')
            .setStyle(ButtonStyle.Primary);

        const variation4 = new ButtonBuilder()
            .setCustomId('variation4')
            .setLabel('V4')
            .setStyle(ButtonStyle.Primary);

        const upscale1 = new ButtonBuilder()
            .setCustomId('upscale1')
            .setLabel('U1')
            .setStyle(ButtonStyle.Secondary);

        const upscale2 = new ButtonBuilder()
            .setCustomId('upscale2')
            .setLabel('U2')
            .setStyle(ButtonStyle.Secondary);

        const upscale3 = new ButtonBuilder()
            .setCustomId('upscale3')
            .setLabel('U3')
            .setStyle(ButtonStyle.Secondary);

        const upscale4 = new ButtonBuilder()
            .setCustomId('upscale4')
            .setLabel('U4')
            .setStyle(ButtonStyle.Secondary);

        const row1 = new ActionRowBuilder()
            .addComponents(upscale1, upscale2, upscale3, upscale4);

        const row2 = new ActionRowBuilder()
            .addComponents(variation1, variation2, variation3, variation4);

        const imageMessage = await message.channel.send({ content: Imagine.uri, components: [row1, row2] })

        const filter = i => ['variation1', 'variation2', 'variation3', 'variation4', 'upscale1', 'upscale2', 'upscale3', 'upscale4'].includes(i.customId);

        const collector = imageMessage.createMessageComponentCollector({ filter, time: 1500000 });

        collector.on('collect', async i => {
            const index = Number(i.customId.slice(-1));

            if (i.customId.startsWith('variation')) {
              const Variation = await midjourneyClient.Variation(
                Imagine.content,
                index,
                Imagine.id,
                Imagine.hash,
                async (uri, progress) => {
                  console.log("Variation URI:", uri, "Progress:", progress);
                  if (uri.endsWith('.webp')) {
                    await message.reply(`Bot is cooking... \nCurrent progress: ${progress} \nURL: ${uri}`);
                  }
                }
              );
              await message.reply({ content: Variation.uri, components: [row1, row2] });
            }

            if (i.customId.startsWith('upscale')) {
              const Upscale = await midjourneyClient.Upscale(
                Imagine.content,
                index,
                Imagine.id,
                Imagine.hash,
                async (uri, progress) => {
                  console.log("Upscale URI:", uri, "Progress:", progress);
                  if (uri.endsWith('.webp')) {
                    await message.reply(`Bot is cooking... \nCurrent progress: ${progress} \nURL: ${uri}`);
                  }
                }
              );
              await message.reply({ content: Upscale.uri });
            }
        });
      } catch (error) {
        console.error(`Error encountered: ${error.message}`); // Debug log
      }
    }
});

client.login('')
crazyramirez commented 1 year ago

Try changing this line

if (uri.endsWith('.webp')) { await botMessage.edit(Bot is cooking... \nCurrent progress: ${progress} \nURL: ${uri}); }

and get the progress that not depends on your uri extension. Note that you can check the image is finished when progress sets “done”

also if you look at the example files, you can access to your end progress using async function .then .catch

main() .then(() => { console.log("finished"); process.exit(0); }) .catch((err) => { console.log("finished"); console.error(err); process.exit(1); });

NotReks commented 1 year ago

problem is, in the terminal most of the time the uri doesnt even show up, can you help me diagnose this directly? i dont know what im doing