Search code examples
pythondiscord.pybots

Application Bot print questions in embed


i would like the application bot to print the questions in the embed. So it would go something like this,

Question 1

Question Asnwer

Question 2

Question Asnwer

Etc etc

This is my code

import discord
import json
from discord.ext import commands
from discord.utils import get
import inspect
from discord import colour
from discord import user
from discord.ext import commands
from discord.ext.commands import Bot
bot = Bot("?")

intents = discord.Intents.all()
client = discord.Client(intents=intents)
#------------------------
channel_id = 1144768805499834409 # sends application to when it is done
token = "BOT TOKEN"
# ------------------------
prefix = '?'
questions = {
    1: "What is your In-Game Name?",
    2: "Why do you want to be a police constable in BSRP",
    3: "In your own words,  what are your strengths and weaknesses? ",
    4: "What can you bring to the Metropolitan Police Service?",
    5: "Can you tell us a time you faced a difficult challenge and how you dealt with it?",
    6: "Where do you see yourself in 3 months time?",
    7: "What is your discord name and tag?"
}
max_questions = len(questions)
is_open = True

@client.event
async def on_message(message):
    global is_open
    if not message.content.startswith(prefix) or message.author.bot:
        return

    args = message.content[len(prefix):].split()
    command = args.pop(0).lower()

    if command == 'apply':
        if not is_open:
            await message.channel.send("Sorry, Applications are currently closed.")
            return
        user = await message.author.create_dm()
        await user.send("Hey! Welcome to your police Constable application! Your application has started. You have 3 minutes to complete it. Please rember to put lots of detail into youe respones and think about your answers")
        await message.channel.send("Application has been sent to your DM's, Please check for messages from BSRP Bot")
       
        application = {'userId': message.author.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 client.wait_for('message', check=lambda m: m.author == message.author 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)

#### Submitted application embed #######

        channel = client.get_channel(channel_id)
        embed = discord.Embed(title='Police Constable Application: ' + message.author.display_name)
        for i in range(1, max_questions+1):
            embed.add_field(name=f'Question {i}: ', value=application[f'question{i}'], inline=True)
        await channel.send(embed=embed)

        await user.send('Thank you for applying! Your Application will now be reviewed! after it has been reviewed a member of the training team will contact you! Please do dont open support tickets unless it has been more then 48 hours since you applied. Best of luck!!')

    elif command == 'open' and message.author.guild_permissions.administrator:
        is_open = True
        await message.channel.send("Applications are now open.")

    elif command == 'close' and message.author.guild_permissions.administrator:
        is_open = False
        await message.channel.send("Applications are now closed.")

the bot works fine but can't work how to put the questions into the embed, the bot is in python. at the moment it sends a embed in the channel like this

Question 1 Answer

Question 2 Answer


Solution

  • If I understand your question correctly this is what you're looking for?

    enter image description here

    You will get this with the following code:

    #### Submitted application embed #######
    
            channel = client.get_channel(channel_id)
            embed = discord.Embed(title='Police Constable Application: ' + message.author.display_name)
            for i in range(1, max_questions+1):
                myval = f'{questions[i]}\n\n' + '_' + application[f'question{i}'] + '_'
                embed.add_field(name=f'Question {i}: ', value=myval, inline=True)
            await channel.send(embed=embed)