xtekky / gpt4free-discord

Gpt4Free basic disord bot, streamed responses, gpt-4 and more
GNU General Public License v3.0
177 stars 27 forks source link

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

Closed Sui-Xing closed 1 year ago

Sui-Xing commented 1 year ago

I have an problem when input "/create" command in discord channel


[2023-06-14 04:22:15] [ERROR   ] discord.app_commands.tree: Ignoring exception in command 'create'
Traceback (most recent call last):
  File "C:\Users\Jupiter\Downloads\gpt4free-discord-main\main.py", line 67, in say
    Interaction.response.defer()
    ^^^^^^^^^^^
NameError: name 'Interaction' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Jupiter\tools\miniconda\envs\gpt4free_env\Lib\site-packages\discord\app_commands\commands.py", line 828, in _do_call
    return await self._callback(interaction, **params)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Jupiter\Downloads\gpt4free-discord-main\main.py", line 86, in say
    await interaction.response.send_message(f'an error occured: {e}')
  File "C:\Users\Jupiter\tools\miniconda\envs\gpt4free_env\Lib\site-packages\discord\interactions.py", line 799, in send_message
    await adapter.create_interaction_response(
  File "C:\Users\Jupiter\tools\miniconda\envs\gpt4free_env\Lib\site-packages\discord\webhook\async_.py", line 219, in request
    raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Jupiter\tools\miniconda\envs\gpt4free_env\Lib\site-packages\discord\app_commands\tree.py", line 1248, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "C:\Users\Jupiter\tools\miniconda\envs\gpt4free_env\Lib\site-packages\discord\app_commands\commands.py", line 853, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Jupiter\tools\miniconda\envs\gpt4free_env\Lib\site-packages\discord\app_commands\commands.py", line 846, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'create' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction
ERROR:discord.app_commands.tree:Ignoring exception in command 'create'
Traceback (most recent call last):
  File "C:\Users\Jupiter\Downloads\gpt4free-discord-main\main.py", line 67, in say
    Interaction.response.defer()
    ^^^^^^^^^^^
NameError: name 'Interaction' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Jupiter\tools\miniconda\envs\gpt4free_env\Lib\site-packages\discord\app_commands\commands.py", line 828, in _do_call
    return await self._callback(interaction, **params)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Jupiter\Downloads\gpt4free-discord-main\main.py", line 86, in say
    await interaction.response.send_message(f'an error occured: {e}')
  File "C:\Users\Jupiter\tools\miniconda\envs\gpt4free_env\Lib\site-packages\discord\interactions.py", line 799, in send_message
    await adapter.create_interaction_response(
  File "C:\Users\Jupiter\tools\miniconda\envs\gpt4free_env\Lib\site-packages\discord\webhook\async_.py", line 219, in request
    raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Jupiter\tools\miniconda\envs\gpt4free_env\Lib\site-packages\discord\app_commands\tree.py", line 1248, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "C:\Users\Jupiter\tools\miniconda\envs\gpt4free_env\Lib\site-packages\discord\app_commands\commands.py", line 853, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Jupiter\tools\miniconda\envs\gpt4free_env\Lib\site-packages\discord\app_commands\commands.py", line 846, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'create' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction
Sui-Xing commented 1 year ago

I've solved this problem, need to add code to delay sending message to discord when poe is connected, it's because it takes too long to create poe connection/proxy, especially when using proxy to connect poe. Below is the modified code.

@bot.tree.command(name='create', description='prompt a language model (gpt-4, claude etc...)')
@app_commands.describe(prompt='prompt', model='model')
async def say(interaction: discord.Interaction, prompt: str, model: str = 'gpt-4'):
    try:

        print(interaction.user.name, prompt, model)
        await interaction.response.defer(ephemeral=True, thinking=True)
        base = f'*model*: `{model}`\n'
        system = 'system: your response will be rendered in a discord message, include language hints when returning code like: ```py ...```, and use * or ** or > to create highlights ||\n prompt: '

        token = random.choice(open('tokens.txt', 'r').read().splitlines())
        client = poe.Client(token.split(':')[0],proxy="http://127.0.0.1:7890")
        print("token.split(':')[0]:",token.split(':')[0])

        await interaction.followup.send(base)

        base += '\n'

        completion = client.send_message(models[model],
                                        system + prompt, with_chat_break=True)
        for token in completion:
            print("token",token)
            base += token['text_new']

            base = base.replace('Discord Message:', '')
            await interaction.edit_original_response(content=base)

    except Exception as e:
        await interaction.response.send_message(f'an error occured: {e}')

bot.run(token)