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
#interaction
1 messages · Page 1 of 1 (latest)
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
Can you show some code?
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
Connecting to the payment system API, where the token is stored, etc.
Code yes, the library did not quite understand the question
Do you use any requests?
Library latest version py-cord ( 2.4.1 )
Yes
?tag requests
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
aiohttp comes with py-cord
Thank you very much, you helped me incredibly
that can also cause the unkown interaction stuff
do you respond to the interaction at the button?
Yes, in this part of the code I use at the beginning await interaction.response.defer() and then await interaction.followup.send
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?
Unfortunately, the problem did not disappear; I completely eliminated it from my code requests besides importing it, but the result is the same, and it happened in a place where it never existed
can you try it with await interaction.response.send_message instead of await interaction.followup.send
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?
When I copied the text to discord
Came out this
Here is the video, that is, the first time there was an error, the second time everything worked
And in the hosting logs: Unknown Interaction