Bot posting embed 7 times

I have got this application bot and made some changes to it but everytime we finsh answering the questions the posts the embed 7 times as well as sending the "thank you" meaasage 7 times in the DM’s

Im looking for the bug but can’t work it out, here 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 = "MY 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

async def on_message(message):
    global is_open
    if not message.content.startswith(prefix) or

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

    if command == 'apply':
        if not is_open:
            await"Sorry, Applications are currently closed.")
        user = await
        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"Application has been sent to your DM's, Please check for messages from BSRP Bot")
        application = {'userId':}
        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: == and == user, timeout=300)
            application[f'question{i}'] = response.content

            with open('applications.json', 'r') as f:
                data = json.load(f)
        except (FileNotFoundError, json.JSONDecodeError):
            data = []

        with open('applications.json', 'w') as f:
            json.dump(data, f)

        channel = client.get_channel(channel_id)
        embed = discord.Embed(title='Police Constable Application: ' +
        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)
            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
        is_open = True
        await"Applications are now open.")

    elif command == 'close' and
        is_open = False
        await"Applications are now closed.")

async def on_ready():
    print(f"I'm Alive {bot.user}")

The bot only needs to post the respone Embed and DM the user once instead of 7 times

>Solution :

max_questions = len(questions) # 7
for i in range(1, max_questions+1):
  await user.send('Thank you for applying!...')

You have a loop that runs 7 times, and in every loop, you send the Thank you! message. It looks like you need to pull that user.send('Thank you!') line one indent to the left, so it’s not in the loop, and won’t get executed 7 times.

Leave a Reply