EQUENOS / dislash.py

A Python wrapper for discord slash-commands and buttons, designed to extend discord.py.

Home Page:https://dislashpy.readthedocs.io/en/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

LEv145 opened this issue · comments

Code:

from dislash import slash_commands
from dislash.interactions import *
from discord.ext import commands
from pyqiwip2p import QiwiP2P
from pyqiwip2p.types import QiwiCustomer, QiwiDatetime

from discord import Embed

import random
import string
import secrets
...
    def create_bill(self, amount, lifetime=45):
        p2p = QiwiP2P(auth_key=self.QIWI_PRIV_KEY)

        # Random bill id
        alphabet = string.ascii_letters + string.digits
        bill_id = ''.join(secrets.choice(alphabet) for i in range(20))

        try:
            p2p.check(bill_id=bill_id).status
        except TypeError: # If bill_id doesn't exist
            bill = p2p.bill(bill_id=bill_id, amount=amount, lifetime=lifetime)
            if p2p.check(bill_id=bill_id).status == "WAITING":
                return (bill_id, str(bill.pay_url))

        # Gegenerate
        return self.create_bill(amount, lifetime)


    @slash_commands.command(
        guild_ids=test_guilds,
        ... 
    )
    async def donate(self, interact):
        amount = interact.data.get("amount")
        bill_id, url = self.create_bill(int(amount), 45)
        await interact.reply(content="OK", embed=Embed(title="Donate Link!", url=url))
...

And when used, the error is called: discard.errors.Not Found: 404 Not Found (error code: 10062): Unknown interaction

According to tests, I found out that the bug most likely occurs because of the line:
bill = p2p. bill(bill_id=bill_id, amount=amount, lifetime=lifetime)

But I couldn't find out why it was happening

Now the code looks like this:

...
    async def donate(self, interact):
        amount = interact.data.get("amount")
        await interact.reply("Loading...")
        bill_id, url = self.create_bill(int(amount), 45)
        await interact.edit(content="OK", embed=Embed(title="Donate Link!", url=url))
...

And this code works, but it has 1 minus, when using the ephemeral=True parameter:

...
    async def donate(self, interact):
        amount = interact.data.get("amount")
        await interact.reply("Loading...", ephemeral=True)
        bill_id, url = self.create_bill(int(amount), 45)
        await interact.edit(content="OK", embed=Embed(title="Donate Link!", url=url))
...

A new error is raised: TypeError: There's nothing to edit. Send a reply first.

The reason is that you can only use inter.reply once, because interaction token is one-off.
If you need to send more messages, use inter.channel.send instead.

Anyways, I'm going to upgrade inter.reply method so it automatically detects whether it should reply using an interaction token or channel.send.

The last issue is caused by the nature of ephemeral messages. Those are never stored in discord and they can't be edited because of that.