下面是代码
@bot.tree.command(description="create a txt with chat-gpt")
async def gpt(interaction: discord.Interaction, *, prompt:str):
async with aiohttp.ClientSession() as session:
payload = {
"model":"text-davinci-003",
"prompt":prompt,
"temperature": 0.5,
"max_tokens": 50,
"presence_penalty": 0,
"frequency_penalty": 0,
"best_of": 1,
}
headers = {"Authorization": f"Bearer {API_KEY}"}
async with session.post("https://api.openai.com/v1/completions", json=payload, headers=headers) as resp:
response = await resp.json()
em = discord.Embed(title="Chat gpt’s responce:", description=response)
await interaction.response.defer()
await asyncio.sleep(delay=0)
await interaction.followup.send(embed=em)
当我尝试使用slash命令时,它将此作为错误代码告诉我
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/haoroux/.local/lib/python3.10/site-packages/discord/app_commands/tree.py", line 1242, in _call
await command._invoke_with_namespace(interaction, namespace)
File "/home/haoroux/.local/lib/python3.10/site-packages/discord/app_commands/commands.py", line 887, in _invoke_with_namespace
return await self._do_call(interaction, transformed_values)
File "/home/haoroux/.local/lib/python3.10/site-packages/discord/app_commands/commands.py", line 880, in _do_call
raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'gpt' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction
我真的找不到解决办法,即使我尝试了一切,所以如果你有一些时间,请帮助我
我更改了延迟,还尝试将embed = em放入response. defer()中,我尝试覆盖embed,但没有执行任何操作,它不起作用
1条答案
按热度按时间rks48beu1#
我认为问题是你的交互在你响应之前就超时了--因此出现了
404
错误。你应该把defer()
放得更高--最好是尽快并且在你调用任何API之前。