-1

For my first project in Python I am trying to create a Discord bot. My project is on a GitHub repo on public. Obviously I don't want my private bot key be accessible by anyone. I was wondering if there is a way for me to declare a variable on my local disk where I can put my key and just access it from my project. This way, anyone can consult my repo without having access to my key.

Thanks

1 Answers1

0

You need to save the key to some form of persistent memory. For this you can simply save a file on your hard drive and read it when your script starts.

def main():
    bot_key = ''
    with open('./discord_key.txt', 'r') as f: bot_key = f.read()

if __name__ == '__main__':
    main()
BTables
  • 4,413
  • 2
  • 11
  • 30