2 months ago
i am not able to depoly this project i am facing some issue related to bot token can anyone help me out ?
56 Replies
2 months ago
Did you make sure to set environment variables for the service?
2 months ago
Click on the service and go to the variables tab, then add your variables.
2 months ago
Make sure to redeploy after.
2 months ago
You need to add it to the service.
2 months ago
Shared variables just means other services have access to it.
2 months ago
^
2 months ago
Not service settings. Click on the service, then there should be a variables tab.
2 months ago

2 months ago
Delete that photo now
2 months ago
You just leaked your token
2 months ago
But yes, redeploy your service.
2 months ago
Yes.
@pepper man i am facing big issue basicaly A Discord bot that converts USD amounts into Litecoin (LTC) using real-time prices from Binance. Users can DM the bot with amounts like 10 or 10$, and it replies with a clean message showing the USD amount, equivalent LTC, and current LTC price.
but it is not able to fetch ltc price idk why before hosting bot its working properly
`import discord
import requests
import re
import os
Get Discord token from environment variable
TOKEN = os.getenv("DISCORDTOKEN") if TOKEN is None: raise ValueError("DISCORDTOKEN environment variable is not set!")
Discord intents
intents = discord.Intents.default()
intents.messages = True
intents.dm_messages = True
client = discord.Client(intents=intents)
Function to get real-time LTC price from Binance
def getltcprice():
url = "https://api.binance.com/api/v3/ticker/price?symbol=LTCUSDT"
response = requests.get(url, timeout=10)
response.raiseforstatus() # Error if status != 200
data = response.json()
return float(data["price"])
Bot ready event
@client.event
async def on_ready():
print(f"Bot logged in as {client.user}")
DM handler
@client.event
async def on_message(message):
if message.author == client.user:
return
if isinstance([message.channel](message.channel), discord.DMChannel):
content = message.content.strip()
match = re.fullmatch(r"(\d+(\.\d+)?)(\$)?", content)
if match:
usd = float([match.group](match.group)(1))
try:
ltc_price = get_ltc_price()
ltc = usd / ltc_price
await [message.channel](message.channel).send(
f"**USD Amount:** ${usd:.2f}\n"
f"**Equivalent LTC:** {ltc:.6f} LTC\n"
f"**Live LTC Price:** ${ltc_price:.2f}"
)
except Exception as e:
await [message.channel](message.channel).send(f"⚠️ Could not fetch LTC price: {e}")
else:
await [message.channel](message.channel).send(
"❌ Please send an amount like:\n`10` `10$` `300` `300$`"
)Run bot
client.run(TOKEN)`
You didn't need to send the code, you just needed to send the error message that appeared when you tried running the API request to Binance.
About the DISCORD_TOKEN env variable error, just follow what was sent upwards.
You just sent what the message the discord bot sends, change the code so it logs the error that the API gave.
You can put this at the throw Exception part:
print(f"API error: {e}")2 months ago
add better error handling to see what's actually being returned:
import discord
import requests
import re
import os
TOKEN = os.getenv("DISCORD_TOKEN")
if TOKEN is None:
raise ValueError("DISCORD_TOKEN environment variable is not set!")
# Discord intents
intents = discord.Intents.default()
intents.messages = True
intents.dm_messages = True
client = discord.Client(intents=intents)
def get_ltc_price():
url = "https://api.binance.com/api/v3/ticker/price?symbol=LTCUSDT"
try:
response = requests.get(url, timeout=10)
response.raise_for_status() # Fixed: was raiseforstatus()
data = response.json()
# Add logging to see what we got
print(f"Binance API response: {data}")
# Check if 'price' key exists
if "price" not in data:
print(f"Error: 'price' key not found. Full response: {data}")
raise KeyError(f"Price key not found in response: {data}")
return float(data["price"])
except Exception as e:
print(f"Error fetching LTC price: {e}")
raise
# Bot ready event
@client.event
async def on_ready():
print(f"Bot logged in as {client.user}")
# DM handler
@client.event
async def on_message(message):
if message.author == client.user:
return
if isinstance(message.channel, discord.DMChannel):
content = message.content.strip()
match = re.fullmatch(r"(\d+(\.\d+)?)(\$)?", content)
if match:
usd = float(match.group(1))
try:
ltc_price = get_ltc_price()
ltc = usd / ltc_price
await message.channel.send(
f"**USD Amount:** ${usd:.2f}\n"
f"**Equivalent LTC:** {ltc:.6f} LTC\n"
f"**Live LTC Price:** ${ltc_price:.2f}"
)
except Exception as e:
await message.channel.send(f"⚠️ Could not fetch LTC price: {e}")
else:
await message.channel.send(
"❌ Please send an amount like:\n`10` `10$` `300` `300$`"
)
# Run bot
client.run(TOKEN)Status changed to Solved brody • about 2 months ago
2 months ago
The trial lasts for 30 days or when you use up $5 worth of credits.



