Python discord bot slash command delay error


I was making a discord bot using Python. I made a code that tells weather information using nextcode. And when you run the command, it says, “Application didn’t respond.” And in the error code

Ignoring exception in command <nextcord.application_command.SlashApplicationCommand object at 0x000001FA23F47020>:
Traceback (most recent call last):
  File "C:\Users\taeho\AppData\Local\Programs\Python\Python312\Lib\site-packages\nextcord\", line 918, in invoke_callback_with_hooks
    await self(interaction, *args, **kwargs)
  File "c:\Users\taeho\OneDrive\바탕 화면\음악봇\", line 48, in slash
    await ctx.send("현재 온도 : {}\n체감 온도".format(온도결과, 체감온도), ephemeral=True)
  File "C:\Users\taeho\AppData\Local\Programs\Python\Python312\Lib\site-packages\nextcord\", line 540, in send
    return await self.response.send_message(
  File "C:\Users\taeho\AppData\Local\Programs\Python\Python312\Lib\site-packages\nextcord\", line 896, in send_message      
    await adapter.create_interaction_response(
  File "C:\Users\taeho\AppData\Local\Programs\Python\Python312\Lib\site-packages\nextcord\webhook\", line 195, in request
    raise NotFound(response, data)
nextcord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

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

nextcord.errors.ApplicationInvokeError: Command raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

It pops up like this

And my command code is like this

@bot.slash_command(name="날씨", description="날씨를 볼 수 있습니다")
async def slash(ctx, 지역:str=nextcord.SlashOption(description="지역을 입력하세요.")):
    검색 = 지역+"날씨"
    url = "" + 검색
    hdr = {'User-Agent': 'Mozilla/5.0'}
    req = requests.get(url, headers=hdr)
    html = req.text
    bsObj = bs4.BeautifulSoup(html, "html.parser")

    온도 = bsObj.find('div', class_='temperature_text')
    온도텍 = 온도.text
    온도결과 = re.sub(r'[^0-9.]', '', 온도텍.strip().split('°')[0])

    체감온도 = bsObj.find('div', class_='sort')
    체감온도텍 = 체감온도.text
    체감온도결과 = re.sub(r'[^0-9.]', '', 체감온도텍.strip().split('°')[0])
    await ctx.send("현재 온도 : {}\n체감 온도".format(온도결과, 체감온도), ephemeral=True)

Please help me

1 Like

It seems like your command takes longer than 3 seconds to answer. After that, Discord timeouts your command and Nextcord loses access to your interaction. To fix that, you can either move to nextcord.Interaction and use nextcord.Interaction.response.defer(), OR simply send a message before all your processing code and then send your actual response as a follow-up.