#๐Ÿ”’ How to be correctly organised ?

28 messages ยท Page 1 of 1 (latest)

regal drum
#

Hello everyone!

I'm totally new to Python. I did learned the basics and now trying to learn and understand about making a Discord bot.

I was wondering if there's a way to be organised with the bot commands and stuff instead of writing them all in the main file?

Can I have, say a main.py file that contain the main script to log the bot in, get the token and intents, etc... and then another file like commands.py?

If so, how should I link both file so the bot know it have to go to commands.py to use them when triggered?

I would like to have a good folder structure so it's easier for me to navigate through my scripts instead of having everything in one file... Unless it's a bad idea to separate stuffs?

Maybe something like :

my_discord_bot/
โ”œโ”€โ”€ .env
โ”œโ”€โ”€ main.py
โ”œโ”€โ”€ modules/
โ”‚   โ”œโ”€โ”€ commands.py
โ”‚   โ”œโ”€โ”€ reactions.py
โ”‚   โ”œโ”€โ”€ moderation.py

tell me if I wasn't clear enough. English isn't my main language.

Thanks for your help!

gritty cradleBOT
#

@regal drum

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

regal drum
#

How to be correctly organised ?

wanton solstice
#

leme make an example i feel like i did not explain that welll

wanton solstice
#

def main():
print("Hello, world")
main()

regal drum
#

Oh yeah that's a good idea, thanks! Shouldn't it be combined with import?

regal drum
wanton solstice
regal drum
#

Oh so if it's in the same workspace I don't need to import? Make sense

wanton solstice
#

yeah

merry viper
wanton solstice
#

sheesh day 4 of coding and i feel like a professiona;

regal drum
#

Yeah that's what I'm getting. I guess that's better so I don't have everything in the same file. What a mess lol

regal drum
wanton solstice
#

how do you make a new file lol

regal drum
#

Which IDE are you using?

wanton solstice
#

pycharm

regal drum
#

Oh

#

Dunno sorry I use VSCode... Can't you simply right click in your workspace > New file?

wanton solstice
#

leme try

#

im dumb yes ty your right ๐Ÿคฃ

regal drum
#

haha

#

Alright I got what I needed. Thanks y'all! blobheart

#

!close

gritty cradleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.