代码之家  ›  专栏  ›  技术社区  ›  bsrp23

嵌入式应用程序中的机器人打印问题

  •  0
  • bsrp23  · 技术社区  · 2 年前

    我希望应用程序bot打印嵌入中的问题。所以事情会是这样的,

    问题1

    提问 Asnwer

    问题2

    提问 Asnwer

    等等

    这是我的密码

    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.")
    

    bot运行良好,但无法将问题放入嵌入中,bot是用python编写的。此时,它会在通道中发送这样的嵌入

    问题1 答案

    问题2 答案

    0 回复  |  直到 2 年前
        1
  •  1
  •   sicco14    2 年前

    如果我正确理解了你的问题,这就是你想要的吗?

    enter image description here

    您将通过以下代码获得此结果:

    #### 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)