Skip to content
← Back to Community
How to run additional python files in (discord bot)
Profile icon

I'm trying to clean up my python code so that different parts are in separate files but I'm unsure on how to get these files to run in my main python file. I've done:

from file_name import *

but it says it is unused, and that it is unable to detect undefined names. When i try to run the code in discord, it works fine with any code in but does nothing when i try code from my separate files.

Profile icon
Profile icon

Ok, first add a python file, were going to be using

Second, add this code to


And finally, your going to add this code to

import example #You can do "import <fileName>", so you can apply this to any file!
Profile icon

import filename will run the file. You can then do filename.somethingElse to get a function or variable from the file

from filename import somethingElse will import a specific function or variable from that file. You can then just do somethingElse to use the thing you imported

from filename import * imports all the functions, variables etc from the file and all of them can be access with just their name rather than filename.somethingElse

I think in your case you may just want to do import single_response

Profile icon

@CodingCactus what do you mean by somethingElse please give an example

Profile icon

one way is to go to the shell, and type in python, so replace FILENAME with the file you want to run.