DanielPikilidis / Greek-Courier-Tracker-Bot

A python discord bot that tracks parcels from Greek couriers.
3 stars 0 forks source link

[Bug] "The application did not respond" when i `/add` a packet #3

Closed eimparas closed 5 months ago

eimparas commented 5 months ago

hello i just found your exelent bot to track the parcels carryed from our ....exelent (irony) couriers.

I went to setup your bot on my infastructure to track a package for ELTA but i get the followin error:

The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/discord/bot.py", line 1114, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 375, in invoke
    await injected(ctx)
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 132, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: IndexError: list index out of range
Ignoring exception in command add:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 124, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 982, in _invoke
    await self.callback(ctx, **kwargs)
  File "/bot/main.py", line 98, in add
    update_channel = sqlite3_handler.get_update_channels_for_guild_ids(logger, [ctx.guild.id])[0]
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/discord/bot.py", line 1114, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 375, in invoke
    await injected(ctx)
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 132, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: IndexError: list index out of range
Ignoring exception in command add:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 124, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 982, in _invoke
    await self.callback(ctx, **kwargs)
  File "/bot/main.py", line 98, in add
    update_channel = sqlite3_handler.get_update_channels_for_guild_ids(logger, [ctx.guild.id])[0]
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/discord/bot.py", line 1114, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 375, in invoke
    await injected(ctx)
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 132, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: IndexError: list index out of range
2024-06-02 09:24:33 | Bot is ready.
Ignoring exception in command add:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 124, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 982, in _invoke
    await self.callback(ctx, **kwargs)
  File "/bot/main.py", line 98, in add
    update_channel = sqlite3_handler.get_update_channels_for_guild_ids(logger, [ctx.guild.id])[0]
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/discord/bot.py", line 1114, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 375, in invoke
    await injected(ctx)
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 132, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: IndexError: list index out of range
2024-06-02 09:28:40 | Set updates channel for guild RSS (1125554224491679756) to elta (1246750442789277747)
Ignoring exception in command add:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 124, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 982, in _invoke
    await self.callback(ctx, **kwargs)
  File "/bot/main.py", line 98, in add
    update_channel = sqlite3_handler.get_update_channels_for_guild_ids(logger, [ctx.guild.id])[0]
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/discord/bot.py", line 1114, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 375, in invoke
    await injected(ctx)
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 132, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: IndexError: list index out of range

I run it using your guide Here on Docker version 26.1.3, build b72abbb

DanielPikilidis commented 5 months ago

Hi, I'm trying to replicate the issue on my side but so far it's working fine. Can you change the log level to debug? Maybe we can see more information there.

The method get_update_channels_for_guild_ids should return the updates channels for all the guilds. For it to return an empty list it means that it didn't find that guild in the database... which is impossible since 2 lines earlier we can see that it changed the updates channel for that guild.

From the debug logs I want to see the SQL query to make sure everything is working well to that point.

eimparas commented 5 months ago

THis is my yaml compoose:

version: "3.8"
services:
  courier_tracking:
    image: dpikilidis/courier-tracking-bot:latest
    container_name: courier-tracking-bot
    restart: always
    volumes:
      - ./logs:/logs
      - ./data:/data
    environment:
      - LOG_NAME=courier-tracking-bot
      - LOG_LEVEL=DEBUG
      - TRACKER_URL=https://courier-api.danielpikilidis.com
      - DISCORD_KEY=MTE------------------------------WYKdZo

These are the logs after i set the log level to debug and updated the containers

2024-06-02 13:19:43 | [retracted]
2024-06-02 13:19:46 | Bot is ready.
2024-06-02 13:19:46 | Starting update_ids
2024-06-02 13:19:46 | In get_distinct_courier_names executing query: 
        SELECT DISTINCT courier_name FROM Packages

2024-06-02 13:20:24 | In get_update_channels_for_guild_ids executing query: 
        SELECT updates_channel FROM Guilds
        WHERE guild_id IN (1125554224491679756);

Ignoring exception in command add:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 124, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 982, in _invoke
    await self.callback(ctx, **kwargs)
  File "/bot/main.py", line 98, in add
    update_channel = sqlite3_handler.get_update_channels_for_guild_ids(logger, [ctx.guild.id])[0]
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/discord/bot.py", line 1114, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 375, in invoke
    await injected(ctx)
  File "/usr/local/lib/python3.11/site-packages/discord/commands/core.py", line 132, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: IndexError: list index out of range
DanielPikilidis commented 5 months ago

You forgot to edit out the discord token from the logs (in debug mode it prints it at the top). I removed it but it's still visible in the history. It's easier to just generate a new one and leave your previous message here.

After you've done that, try the following. Open the data.sqlite3 file in an database editor (Beekeeper Studio is great for this) and make sure that in the guilds table there is a row for your server. If there is no such row, you should kick the bot from the server and re-invite it so it creates it again in the database. If that's the only server your bot has joined then delete the database altogether and let the bot create it again.

If there is a row for that server then I have no idea what's wrong with the database. I will upload a dev docker image to dockerhub with even more debug logs for that specific command so we can find out the exact value that is returned.

eimparas commented 5 months ago

You forgot to edit out the discord token from the logs (in debug mode it prints it at the top). I removed it but it's still visible in the history. It's easier to just generate a new one and leave your previous message here.

ye it slipped while i quicly passed over the reply .. oops .

What surprised me was discord's response ! from within 30seconds i got a "IMPORTANT DISCORD NOTIFICATION" that blocked my whole client , stating that tokens etc have been leaked and disabled . This amased me ! How quick was the responce ! (ofc all the tokens are nuked now :)

After you've done that, try the following. [....]

Give me some time to get over the semester exams and i will get back to this ...

Fun fact , it just happend to your bot too (using the invite link at the readme) image

DanielPikilidis commented 5 months ago

Oh I might know what's happening. So if the bot gets invited to a server while its offline then it won't create the row in the database. And I never created a way check to look for these new servers. So even thought the bot is in the server, the database doesn't know that. For now I added your server manually to my bots database so it should be working. I will also create a way to check for these new servers and add them during startup.

eimparas commented 5 months ago

hm. i understand.

FYI ill be available for any testing should you need it