'Declaration for "A" not found in specified module' when importing from 're' for a Discord bot

Full context:

I’m newbie at using Python. I use Manjaro Linux with KDevelop as my code editor. I know some basics of Python, and wanted to try to create a discord bot, so I’m following this tutorial. Right now, I’m at video #15. The code is public and can be found here, so I downloaded it to comment it with my notes. Sometimes I like to run it and modify some stuff to see that I’m really understanding what’s happening. Of course, I’m using my own IDs for token and guild.

Issue

I need to use from re import A, but KDevelop is showing me a warning: ‘Declaration for “A” not found in specified module’. Re is a module for regular expression operations, and it’s quite basic.

If I execute it directly on the terminal (which is where I execute the code too) I get:

❯ python
Python 3.10.8 (main, Nov  1 2022, 14:18:21) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> print(re.A)
re.ASCII

So it does recognize the module.

It does not allow me to use / commands (Discord says I’m not allowed to) and it can’t find the !ciao command when I execute it.

ERROR      - discord.ext.commands.bot : Ignoring exception in command None
discord.ext.commands.errors.CommandNotFound: Command "ciao" is not found
2023-01-14 14:55:48 ERROR    discord.ext.commands.bot Ignoring exception in command None
discord.ext.commands.errors.CommandNotFound: Command "ciao" is not found

Discussion:

I’ve asked on Reddit and someone told me that it could be an issue with KDevelop, which doesn’t load the module correctly. I checked the whole app and couldn’t find anything about it (I could have missed it, though, I’m a human, after all). But even if, it doesn’t explain why the code isn’t working when I’m using the original code (with my IDs), but it does on the video.

I’d ignore that as an editor issue. It would be nice to fix but probably not the cause of your other problems. But keep it in mind if you run into other issues with the re module, as this could be a smoking gun.

This could be the issue. It may or may not be re-related, but this is itself a problem, as it’s making your life harder. Unfortunately I can’t find where that error line is coming from (a quick search of the GItHub repo didn’t show it up), but if you can locate the place where this “Ignoring exception” line is produced, try to add extra logging to show WHAT exception is being ignored. And then, if that turns out to be an AttributeError looking up re.A, that’s where to look. If it turns out to be something else, look there instead.

You might be very VERY lucky and be able to get exception details just by looking in the log, just above the lines you showed us. I doubt that it’ll be that easy, but worth a quick look, just in case :slight_smile: More likely, you’ll need to go mess with the source code and make it output more information.

1 Like

Thanks! it turns out to be a bug, so I reported it and it works nicely again! :blush:

Ah, awesome! Glad it’s solved!

1 Like