Spaces:
Running
Running
defer and followup send the command response
Browse files- discord_bot.py +11 -9
discord_bot.py
CHANGED
@@ -26,36 +26,38 @@ async def greet(interaction: discord.Interaction, name: str):
|
|
26 |
|
27 |
@tree.command(name="get-kudos", description="The amount of Kudos this user has.")
|
28 |
async def getKudos(interaction: discord.Interaction):
|
|
|
29 |
async with HordeAPI.getUserDetails() as details:
|
30 |
if "kudos" not in details:
|
31 |
-
await interaction.
|
32 |
return
|
33 |
-
await interaction.
|
34 |
|
35 |
@tree.command(name="generate-status", description="Retrieve the status of an Asynchronous generation request.")
|
36 |
async def generateStatus(interaction: discord.Interaction, id: str):
|
|
|
37 |
async with HordeAPI.generateCheck(id) as details:
|
38 |
if "kudos" not in details:
|
39 |
-
await interaction.
|
40 |
return
|
41 |
if bool(details["is_possible"]) == False:
|
42 |
-
await interaction.
|
43 |
return
|
44 |
if bool(details["faulted"]) == True:
|
45 |
-
await interaction.
|
46 |
return
|
47 |
if bool(details["done"]) == True:
|
48 |
async with HordeAPI.generateStatus(id) as generationDetail:
|
49 |
if "generations" not in generationDetail:
|
50 |
-
await interaction.
|
51 |
for i in range(len(generationDetail["generations"])):
|
52 |
-
await interaction.
|
53 |
return
|
54 |
if int(details["processing"]) > 0:
|
55 |
total = int(details["finished"]) + int(details["processing"]) + int(details["queue_position"]) + int(details["restarted"]) + int(details["waiting"])
|
56 |
-
await interaction.
|
57 |
return
|
58 |
-
await interaction.
|
59 |
|
60 |
@bot.command()
|
61 |
async def ping(ctx):
|
|
|
26 |
|
27 |
@tree.command(name="get-kudos", description="The amount of Kudos this user has.")
|
28 |
async def getKudos(interaction: discord.Interaction):
|
29 |
+
await interaction.response.defer()
|
30 |
async with HordeAPI.getUserDetails() as details:
|
31 |
if "kudos" not in details:
|
32 |
+
await interaction.followup.send(f'Error: {details["code"]} {details["reason"]} {details["rc"]}')
|
33 |
return
|
34 |
+
await interaction.followup.send(f'The amount of Kudos this user has is {details["kudos"]}')
|
35 |
|
36 |
@tree.command(name="generate-status", description="Retrieve the status of an Asynchronous generation request.")
|
37 |
async def generateStatus(interaction: discord.Interaction, id: str):
|
38 |
+
await interaction.response.defer()
|
39 |
async with HordeAPI.generateCheck(id) as details:
|
40 |
if "kudos" not in details:
|
41 |
+
await interaction.followup.send(f'Check Error: {details["code"]} {details["reason"]} {details["rc"]}')
|
42 |
return
|
43 |
if bool(details["is_possible"]) == False:
|
44 |
+
await interaction.followup.send("This generation is impossible.")
|
45 |
return
|
46 |
if bool(details["faulted"]) == True:
|
47 |
+
await interaction.followup.send("This generation is faulted.")
|
48 |
return
|
49 |
if bool(details["done"]) == True:
|
50 |
async with HordeAPI.generateStatus(id) as generationDetail:
|
51 |
if "generations" not in generationDetail:
|
52 |
+
await interaction.followup.send(f'Status Error: {generationDetail["code"]} {generationDetail["reason"]} {generationDetail["rc"]}')
|
53 |
for i in range(len(generationDetail["generations"])):
|
54 |
+
await interaction.followup.send(generationDetail["generations"][i]["img"])
|
55 |
return
|
56 |
if int(details["processing"]) > 0:
|
57 |
total = int(details["finished"]) + int(details["processing"]) + int(details["queue_position"]) + int(details["restarted"]) + int(details["waiting"])
|
58 |
+
await interaction.followup.send(f'Processing image: {details["processing"]}/{total}')
|
59 |
return
|
60 |
+
await interaction.followup.send(f'Position in queue: {details["queue_position"]}, wait time: {details["wait_time"]}s')
|
61 |
|
62 |
@bot.command()
|
63 |
async def ping(ctx):
|