Task. A program for copying data from an Excel table and pasting it into the Discord command line (Midjourney), using the openpyxl library for working with Excel.
Problem.
Not copied from Excel
It gives the following error.
Discord 1.0.9013
Exit from the secondary instance.
**************
import subprocess
import time
from openpyxl import load_workbook
# Opening an Excel file
workbook = load_workbook('c:\AutomationMJ\copyExcelTOmj.xlsx')
# Selecting a letter in an Excel table
worksheet = workbook['Sheet1']
# List of cells from which to copy data
cells_to_copy = ['A1', 'A2', 'A3']
# Loop for each cell
for cell_reference in cells_to_copy:
# Get the value from the selected cell
cell_value = worksheet[cell_reference].value
# Opening Discord in the background and passing a value via standard input
command = ['C:\\Users\\irave\\AppData\\Local\\Discord\\app-1.0.9013\\Discord.exe', '/imagine', ' ' + str(cell_value)]
process = subprocess.Popen(command, stdin=subprocess.PIPE)
process.communicate()
# Delay of 10 seconds before opening the next Discord process
time.sleep(10)
Dos it work outside of the loop also with one vaule?
Eg add
print(cell_value)
on line 18.
Test like this.
import subprocess
cell_vaule = "A dog in space"
command = ['C:\\Users\\irave\\AppData\\Local\\Discord\\app-1.0.9013\\Discord.exe', '/imagine', ' ' + str(cell_value)]
process = subprocess.Popen(command, stdin=subprocess.PIPE)
process.communicate()
Or with
run()
import subprocess
cell_vaule = "A dog in space"
command = ['C:\\Users\\irave\\AppData\\Local\\Discord\\app-1.0.9013\\Discord.exe', '/imagine', ' ' + str(cell_value)]
out = subprocess.run(command , capture_output=True)
print(out.stdout.decode())
I use Midjourney and it return a Image format .png,do you have command from
command line
that work and give you raw .png format back?
(Jun-01-2023, 11:42 AM)snippsat Wrote: [ -> ]Dos it work outside of the loop also with one vaule?
Eg add print(cell_value)
on line 18.
Test like this.
[python]import subprocess
thanks for the help.
But none of these options work. So the problem is different.
(Jun-01-2023, 11:42 AM)snippsat Wrote: [ -> ]I use Midjourney and it return a Image format .png,do you have command from command line
that work and give you raw .png format back?
All png files generated in MJ can be downloaded in one archive. there is no need to copy each file separately.
I have not look if Midjourney has an Api,so if search
How to Use the Missing Midjourney API.
Quote:If you want to create images using Midjourney, you’re stuck using Discord.
Sort of.
Just writing a bog-standard Discord bot won’t work because the Midjourney bot expects “/imagine” and then “tab” and then your prompt. It’s tedious.
Unfortunately, since it’s a fake gui operator waiting for events,
I haven’t quite got it modified to create those database entries.
In theory it should be possible to get the attachments and save them – work in progress!
So there is an
Api but:
Quote:The API is stopping it’s operation but you can purchase it’s source code.
import discord
from discord.ext import commands
from openpyxl import load_workbook
# Discord Bot Token
TOKEN = 'YOUR_DISCORD_BOT_TOKEN'
# Excel File Path
EXCEL_FILE = 'path_to_your_excel_file.xlsx'
# Discord Channel ID
CHANNEL_ID = 'your_discord_channel_id'
# Initialize the Discord Bot
bot = commands.Bot(command_prefix='!')
# Event: When the bot is ready
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')
print('-----')
# Custom Command: Copy and Paste Excel Data to Discord
@bot.command()
async def copy_paste_excel(ctx):
# Load the Excel workbook
workbook = load_workbook(EXCEL_FILE)
# Select the active sheet
sheet = workbook.active
# Iterate over the rows in the Excel table
for row in sheet.iter_rows(min_row=2, values_only=True):
# Format the row data as a string
row_data = ' '.join(str(cell) for cell in row if cell is not None)
# Send the row data to the Discord channel
channel = bot.get_channel(CHANNEL_ID)
await channel.send(row_data)
await ctx.send('Excel data copied and pasted to Discord.')
# Run the Discord bot
bot.run(TOKEN)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Make sure to replace 'YOUR_DISCORD_BOT_TOKEN' with your Discord bot token, 'path_to_your_excel_file.xlsx' with the actual path to your Excel file, and 'your_discord_channel_id' with the ID of the Discord channel where you want to send the data.
To use the bot, you can invite it to your server and use the command !copy_paste_excel to copy the data from the Excel table and paste it into the specified Discord channel.
Please note that you need to have the necessary dependencies (discord.py, openpyxl) installed for this script to work. You can install them using pip install discord.py openpyxl.