#I AM NEW IN PYTHON AND MY BOT DOESNT WORKS
1 messages · Page 1 of 1 (latest)
When setting up your bot, avoid hardcoding your token directly in the code. Instead, use environment variables:
- Install
python-dotenvwithpip install python-dotenv. - Create a
.envfile at the root of your project. - Add your token to the
.envfile:TOKEN=<your bot token>. - Use the token in your code as follows:
import discord
import os
from dotenv import load_dotenv
load_dotenv()
bot = discord.Bot()
# Your code here
bot.run(os.getenv("TOKEN"))