added support for .env filea nd made a new key

This commit is contained in:
Tabby 2025-11-02 15:20:03 +11:00
parent 9dc18b86a2
commit c401709ce9
2 changed files with 12 additions and 10 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
.godot/ .godot/
/android/ /android/
environment.env environment.env
.env

21
main.gd
View file

@ -7,13 +7,14 @@ var interactions = {}
var application_commands = {} var application_commands = {}
#func _load_bot_token() -> String: func _load_bot_token() -> String:
## read from .env file DISORD_BOT_TOKEN # read from .env file DISORD_BOT_TOKEN
#var lines = FileAccess.get_file_as_string(".env").split("\n") var lines = FileAccess.get_file_as_string(".env").split("\n")
#for line in lines: #print(lines)
#if line.begins_with("DISCORD_BOT_TOKEN="): for line in lines:
#return line.split("=")[1] if line.begins_with("DISCORD_BOT_TOKEN="):
#return "" return line.split("=")[1]
return ""
func _ready() -> void: func _ready() -> void:
var bot = DiscordBot.new() var bot = DiscordBot.new()
@ -22,9 +23,9 @@ func _ready() -> void:
# Try to read token from global environment variables # Try to read token from global environment variables
var token = OS.get_environment("DISCORD_BOT_TOKEN") var token = OS.get_environment("DISCORD_BOT_TOKEN")
if not token or (token and len(token) < 10): if not token or (token and len(token) < 10):
# Read token from local .env file #Read token from local .env file
#token = _load_bot_token() token = _load_bot_token()
token = "MTQzMzAyNTMwMzYzODQ0MjAzNQ.G3r4My.IdnvCw6xTBfoitEzvhPgxeErSDgcMCsznmLnvI"
bot.TOKEN = token bot.TOKEN = token
#bot.INTENTS = 4609 #bot.INTENTS = 4609