import discord import requests import json import os import asyncio # Create an instance of Intents intents = discord.Intents.default() intents.message_content = True # Enable message content events 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 # Change the command trigger to "/prompt" if message.content.startswith('/prompt'): input_text = message.content[len('/prompt'):].strip() if input_text: # Mention the user in the response user_mention = message.author.mention print(f'Received message: {message.content}') # Send typing indicator print(f'Sending typing indicator...') async with message.channel.typing(): print(f'Typing indicator sent.') # Simulate a delay (you can adjust this based on the actual response time) print(f'Simulating delay...') await asyncio.sleep(2) # Generate the prompt print(f'Generating prompt...') prompt = get_prompt(input_text) # Reply directly to the input message 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.' # Replace 'YOUR_BOT_TOKEN' with the actual token you obtained from the Discord Developer Portal print('Starting the bot...') client.run('MTE2OTIzNDc0ODc1Mzg0NjMxMg.GOlz8M.rQlvjfQWLYPNpEhWVQ0vJ7sUw_IV0TooMdN8Os')