#interaction

1 messages · Page 1 of 1 (latest)

pallid oak
#

Actually, sometimes I get an error Unknown Interaction, it happens even when I'm at the beginning of the function await interaction.response.defer() , for example, I haven’t used the bot for a long time, for example 2-3 hours, when I press a button or enter a command it gives this error, when I try again the same situation. And the problem is that this is not only On one person but on many people, and many times

#

There may be a problem with the hosting or the code, please tell me. I would understand if this happened rarely, but it happens regularly

pulsar orbit
#

Can you show some code?

pallid oak
#
class Replenishment(discord.ui.View):
    def __init__(self, urls, id):
      super().__init__(timeout=None)
      self.id = id
      self.urls = urls
      self.add_item(discord.ui.Button(label="Оплатить", url=self.urls))

@discord.ui.button(
      label="Проверить оплату",
      emoji=":ballot_box:",
      style=discord.ButtonStyle.primary,
      custom_id="check"
    )
    async def check(self, button, interaction):
      await interaction.response.defer()
      user_id = str(interaction.user.id)
      connection = sqlite3.connect('database.db')
      cursor = connection.cursor()
      cursor.execute('''SELECT * FROM payment WHERE user_id = ?''', (user_id,))
      payments = cursor.fetchall()
      for payment in payments:
        payment_id = payment[1]
        message_id = payment[3]
        amount = payment[2]
        tarif = payment[5]
  
        currency = "RUB"
        client = AaioAPI()
        payment_info = client.get_payment_info(payment_id)
        if payment_info['status'] == 'in_process':```
#

This is a small part of the payment processing function, I hope this part is complete

pulsar orbit
#

what is that API?

#

is it your own library/code?

pallid oak
pallid oak
pulsar orbit
#

Do you use any requests?

pallid oak
#

Library latest version py-cord ( 2.4.1 )

pallid oak
pulsar orbit
#

?tag requests

ionic geyserBOT
#

Why you should not use the requests library for your bot
requests is a popular HTTP library for Python. It is however not a good option for Discord bots, since it is not async and blocking.

This essentially means that your bot will not be able to execute any code at all while a request is happening. Since requests usually take a few seconds to complete, this can have a detrimental effect on your bot's performance. E.g if a user executes a command that performs a request taking 5 seconds to complete, no one else will be able to use your bot for those 5 seconds.

Please look at using a HTTP library that has async support, such as aiohttp or httpx

pulsar orbit
#

aiohttp comes with py-cord

pallid oak
pulsar orbit
#

that can also cause the unkown interaction stuff

#

do you respond to the interaction at the button?

pallid oak
pallid oak
# pulsar orbit ?tag requests

And in this case, if one of the libraries that I use requires requests , that is, I won’t use it in the code, but it will be installed and imported, will this cause problems?

pallid oak
pulsar orbit
#

can you try it with await interaction.response.send_message instead of await interaction.followup.send

pallid oak
#

This time the problem occurred in another button where it is used await interaction.response.edit_message

#

I can send you the code, is it necessary?

pulsar orbit
#

what is your indentation at the code?

#

Im not sure if it was the right word for it

pallid oak
#

Came out this

#

Here is the video, that is, the first time there was an error, the second time everything worked

pallid oak
#

And in the hosting logs: Unknown Interaction

pallid oak
#

Just tried it on another hosting, same result

#

Maybe it's because of the way I'm doing persistent for button