What would be best to use here when returning the values of a form? I believe both would work but what is best practice?
Code is not fully complete.
import discord
from discord import app_commands
from discord.ext import commands
class UnitCreationForm(discord.ui.Modal, title='Unit Creation Form'):
unit_name = discord.ui.TextInput(
label="Unit Name",
required=True,
)
unit_name_abr = discord.ui.TextInput( # Unit Name Abbreviated
label="Abbreviated Unit Name",
placeholder="For example: USAF",
required=True,
)
unit_desc = discord.ui.TextInput(
label="Unit Description",
style=discord.TextStyle.long,
placeholder="Please describe your unit in detail",
required=True,
min_length=300,
max_length=2000,
)
unit_member_count = discord.ui.TextInput(
label="How many members does your unit have?",
)
unit_member_activity = discord.ui.TextInput(
label="What is your unit's activity?",
placeholder="How many on a typical operation...",
)
async def on_submit(self, interaction: discord.Interaction) -> :
await interaction.response.send_message(f'Thank you for submitting your unit creation form, a member of the staff team will review it within 24 hours. We hope to see {self.unit_name.value} here soon!', ephemeral=True)
unit_data = [self.unit_name.value, self.unit_name_abr.value, self.unit_desc.value, self.unit_member_count.value, self.unit_member_activity.value]
return unit_data
class Unit(commands.Cog):
group = app_commands.Group(name="unit", description="Unit and military affair commands.")
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot
@group.command(name="create", description="This command is used to create a unit.")
async def create(self, interaction: discord.Interaction, user: discord.User = None) -> None:
if user is None:
await interaction.response.send_message("User not specified. Please specify a user.", ephemeral=True)
try:
await interaction.user.send()
So here:
unit_data = [self.unit_name.value, self.unit_name_abr.value, self.unit_desc.value, self.unit_member_count.value, self.unit_member_activity.value]
return unit_data
I am using a list, which would work fine but wondering if it is better to use a dictionary or not for storing and accessing the values.