|
import discord |
|
import requests |
|
import json |
|
import os |
|
import asyncio |
|
|
|
|
|
intents = discord.Intents.default() |
|
intents.message_content = True |
|
|
|
client = discord.Client(intents=intents) |
|
|
|
@client.event |
|
async def on_ready(): |
|
print(f'We have logged in as {client.user}') |
|
|
|
@client.event |
|
async def on_message(message): |
|
if message.author == client.user: |
|
return |
|
|
|
|
|
if message.content.startswith('/prompt'): |
|
input_text = message.content[len('/prompt'):].strip() |
|
if input_text: |
|
|
|
user_mention = message.author.mention |
|
|
|
print(f'Received message: {message.content}') |
|
|
|
|
|
print(f'Sending typing indicator...') |
|
async with message.channel.typing(): |
|
print(f'Typing indicator sent.') |
|
|
|
|
|
print(f'Simulating delay...') |
|
await asyncio.sleep(2) |
|
|
|
|
|
print(f'Generating prompt...') |
|
prompt = get_prompt(input_text) |
|
|
|
|
|
print(f'Replying to message...') |
|
await message.reply(f'{user_mention} Generated Prompt: {prompt}') |
|
print(f'Reply sent.') |
|
|
|
def get_prompt(input_text): |
|
api_url = "https://gustavosta-magicprompt-stable-diffusion.hf.space/api/predict" |
|
headers = {"Content-Type": "application/json"} |
|
payload = {"data": [input_text]} |
|
|
|
print(f'Sending API request...') |
|
response = requests.post(api_url, data=json.dumps(payload), headers=headers) |
|
result = response.json() |
|
|
|
print(f'API response: {result}') |
|
|
|
return result['data'][0] if result['data'][0] else 'Prompt generation failed.' |
|
|
|
|
|
print('Starting the bot...') |
|
client.run('MTE2OTIzNDc0ODc1Mzg0NjMxMg.GOlz8M.rQlvjfQWLYPNpEhWVQ0vJ7sUw_IV0TooMdN8Os') |
|
|