Added /setup command that creates a persistent

Apply button
main
Anorak_1 2023-07-17 12:26:28 +02:00
parent b4483e938d
commit 458259c252
1 changed files with 62 additions and 2 deletions

64
bot.py
View File

@ -37,8 +37,6 @@ async def on_ready():
@bot.slash_command(description = "Command used to apply")
async def apply(ctx):
message = ctx.message
await ctx.response.send_message(content="Application started", ephemeral=True)
user = await ctx.author.create_dm()
@ -162,4 +160,66 @@ class ApplicationModal(discord.ui.Modal):
embed.colour = discord.Colour.red()
await interaction.followup.edit_message(message_id = interaction.message.id, embeds=[emb, embed])
@bot.slash_command(description = "Command used to set up the application prompt")
async def setup(ctx):
embed = discord.Embed(title="**Start your application!**")
embed.add_field(name="Click the button below to start your application", value="", inline=False)
appStartView = ApplicationStartButtonView()
await ctx.response.send_message("Message set up", ephemeral=True)
await ctx.channel.send(embeds=[embed], view=appStartView)
class ApplicationStartButtonView(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
@discord.ui.button(
label="Start application!",
style=discord.ButtonStyle.green,
custom_id=f"persistent:start_application",
)
async def start_app(self, button: discord.ui.Button, interaction: discord.Interaction):
await interaction.response.send_message(content="Application started", ephemeral=True)
user = await interaction.user.create_dm()
await user.send("Hey! Your application has started. You have 300 seconds to complete it.")
application = {'userId': interaction.user.id}
for i in range(1, max_questions+1):
embed = discord.Embed(title=f'Question [{i}/{max_questions}]', description=questions[i])
await user.send(embed=embed)
response = await bot.wait_for('message', check=lambda m: m.author == interaction.user and m.channel == user, timeout=300)
application[f'question{i}'] = response.content
try:
with open('applications.json', 'r') as f:
data = json.load(f)
except (FileNotFoundError, json.JSONDecodeError):
data = []
data.append(application)
with open('applications.json', 'w') as f:
json.dump(data, f)
channel = bot.get_channel(channel_id)
embed = discord.Embed(title='Application: ' + interaction.user.display_name)
for i in range(1, max_questions+1):
embed.add_field(name=f'{questions[i]}', value=application[f'question{i}'], inline=False)
embed.set_footer(text=f"Applicant ID: {interaction.user.id}")
appView = ApplicationButtonsView()
msg = await channel.send(embed=embed, view=appView)
print(msg.id)
data = (msg.id, interaction.user.id, interaction.guild.id)
con = sqlite3.connect("applications.db")
cur = con.cursor()
cur.execute(f"INSERT INTO app_msg_db VALUES (?, ?, ?)", data)
con.commit()
await user.send('Thank you for applying!')
bot.run(TOKEN)