I want to make a command such that when I use it, a form would pop up for me to complete and my responses will be DMed to me and posted in another channel afterwards. Below is the code I used (I referred to multiple YouTube tutorials) in a group cog named modal
; the names and numbers are altered slightly due to privacy and stuff.
I am able to run the bot normally without any errors, and all my other cogs and commands work as normal. However, when I use the modal form command, the bot does not respond at all, despite there bring no errors printed in the console.
The numbers 2
, 3
, 4
, 5
, 6
, 7
and 8
are printed in the console when starting up the bot (why does this happen???), and when I used the modal form command, only number 0
is printed in the console, which might mean that await interaction.response.send_modal(myModal())
is not working for some reason.
What I expected to happen
- When I use the command, console prints
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
15
15
15
15
16
17
18
19
20
- Discord shows me a modal form with 5 questions to complete (all required, paragraph, 1000-character limit), and an embed containing my responses is sent to a text channel and my DMs after I complete the modal form
- The bot responds to the command with a message containing my username and user ID after I complete the modal form
What actually happened
- When I start up the bot, console prints
2
3
4
5
6
7
8
(why???) - When I use the command, console prints
0
(why???) - The bot does not respond to the command (shows “The application did not respond” after a few seconds)
File: commands/slash_commands_modal.py
import discord
from discord import app_commands, ui
from discord.ext import commands
from misc.dicts import DICT
class myModal(ui.Modal, title="Why not working"):
print("2") # debug no.2
a1 = ui.TextInput(
label=DICT["a"][0],
placeholder=DICT["ax"][0],
style=discord.TextStyle.paragraph,
max_length=1000,
required=True
)
print("3") # debug no.3
a2 = ui.TextInput(
label=DICT["a"][1],
placeholder=DICT["ax"][1],
style=discord.TextStyle.paragraph,
max_length=1000,
required=True
)
print("4") # debug no.4
a3 = ui.TextInput(
label=DICT["a"][2],
placeholder=DICT["ax"][2],
style=discord.TextStyle.paragraph,
max_length=1000,
required=True
)
print("5") # debug no.5
a4 = ui.TextInput(
label=DICT["a"][3],
placeholder=DICT["ax"][3],
style=discord.TextStyle.paragraph,
max_length=1000,
required=True
)
print("6") # debug no.6
a5 = ui.TextInput(
label=DICT["a"][4],
placeholder=DICT["ax"][4],
style=discord.TextStyle.paragraph,
max_length=1000,
required=True
)
print("7") # debug no.7
a = [a1,a2,a3,a4,a5]
print("8") # debug no.8
async def on_submit(self, interaction: discord.Interaction):
print("9") # debug no.9
channel = self.bot.get_channel(9999999999999999999)
print("10") # debug no.10
d = f"- Username: **{interaction.user.name}**n- User ID: ||**`{interaction.user.id}`**||"
print("11") # debug no.11
e = discord.Embed(title=f"Form", description=d, colour=0xe74c3c)
print("12") # debug no.12
e.set_footer(text="Form Response")
print("13") # debug no.13
q = DICT["a"]
print("14") # debug no.14
for i, j in zip(q, self.a):
e.add_field(name=i, value=j, inline=False)
print("15") # debug no.15
await channel.send(embed=e)
print("16") # debug no.16
await interaction.response.send_message(f"- Username: **{interaction.user.name}**n- User ID: ||**`{interaction.user.id}`**||nnThe form is done yay", ephemeral=True)
print("17") # debug no.17
user = self.bot.get_user(interaction.user.id)
print("18") # debug no.18
await user.create_dm()
print("19") # debug no.19
await user.dm_channel.send(embed=e)
print("20") # debug no.20
class SlashCmd_Modal(commands.GroupCog, group_name="modal"):
def __init__(self, bot):
self.bot = bot
@app_commands.command(name="form", description="a description")
@app_commands.describe(role="another description")
@app_commands.choices(role = [
app_commands.Choice(name="A", value="a"),
app_commands.Choice(name="B", value="b"),
app_commands.Choice(name="C", value="c"),
app_commands.Choice(name="D", value="d")
])
async def form(self, interaction: discord.Interaction, role: str):
if role == "a":
print("0") # debug no.0
await interaction.response.send_modal(myModal())
print("1") # debug no.1
elif role == "b":
... # similar kind of form but different class
elif role == "c":
... # similar kind of form but different class
elif role == "d":
... # similar kind of form but different class
async def setup(bot):
await bot.add_cog(SlashCmd_Modal(bot))
File: misc/dict.py
DICT = {
"a": [ # questions
"Q1",
"Q2",
"Q3",
"Q4",
"Q5"
],
"ax": [ # placeholders
"P1",
"P2",
"P3",
"P4",
"P5"
]
}
AJ Goh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.