how to increase the waiting time for a response from a discord bot

Viewed 46

I have a piece of code:

        server.register_user(author, nickname)
        server.whitelist_add(nickname)
        embed = discord.Embed(color=0x0bd50b, title='Done!', description=f'Player **{nickname}** added in white list!')
        embed.set_thumbnail(url=ctx.author.avatar_url)
        embed.set_footer(text=f'profile of {author}', icon_url=icon)
        

        await ctx.respond(embed=embed, ephemeral=True)

("server.register_user()" is a regular mysql query that looks like this:

        with connection.cursor() as cursor:
            cursor.execute('insert users(dis_name, nick) values (%s, %s)', (dis_name, name))
            connection.commit()

            now = datetime.now()
            current_time = now.strftime('%H:%M:%S')

            print(f'[{current_time}][ database ] where insert into table users values: {dis_name}, {name}')

another function "whitelist_add(nickname)" works on the same principle.)

this part of the code writes data to the database. And does it sooo long (probably because of the speed of the Internet). And that 's why he writes to me in the chat: "the application did not respond"

and I have a question: is it possible to make the discord server wait longer so that my bot has time to get the info? I use discord.py==1.7.3

1 Answers

Since you are using an interaction you can use the
ctx.defer()
The bot will respond with 'the bot is thinking' rather than "the application did not respond"

        server.register_user(author, nickname)
        server.whitelist_add(nickname)
        embed = discord.Embed(color=0x0bd50b, title='Done!', description=f'Player **{nickname}** added in white list!')
        embed.set_thumbnail(url=ctx.author.avatar_url)
        embed.set_footer(text=f'profile of {author}', icon_url=icon)
        
        await ctx.defer()
        await ctx.respond(embed=embed, ephemeral=True)

Make sure that the indentation is correct if any errors come up

Related