Having some problems with importing class when coding discord bot

Hi, recently when I coded my discord bot, I faced some problems when importing class. I have made sure that the file was in the right place and that the syntax was right. But I can not solve this problem. The issue didn’t happen until recently.

This is what compiler has said.

By the way this is the code that I import class:

import discord
import json
import time
import datetime
import random
import requests
import asyncio
from discord.ext import commands
from core.classes import cog_extension

I have check that the file was in the right location.

I understand that the core module was created by you, and not imported by a repl. Is that true?

1 Like

Yes it is. That one was created by me.

In Python, each package must have a file __init__.py . The presence of this file indicates that the folder in which it is located is a package and that modules can be imported from this folder.

Your core package probably doesn’t have a file __init__.py , so Python doesn’t recognize it as a package. You need to add the file __init__.py (in your case, the file should be empty) to the core folder.

Documentation: 6. Modules — Python 3.12.0 documentation


It finally work. Thank you so much.

You can mark the post that helped you the most as a solution. This way it will be easier for other users to solve a similar problem.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.