Redepoly error
solvfpz
FREEOP

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 ?

Solved$10 Bounty

56 Replies

Did you make sure to set environment variables for the service?


Click on the service and go to the variables tab, then add your variables.


Make sure to redeploy after.


solvfpz
FREEOP

2 months ago

see

1454082718705909800


solvfpz
FREEOP

2 months ago

i did


solvfpz
FREEOP

2 months ago

still not working


You need to add it to the service.


Shared variables just means other services have access to it.


solvfpz
FREEOP

2 months ago

where ?




solvfpz
FREEOP

2 months ago

i cant see any service variable in settings


Not service settings. Click on the service, then there should be a variables tab.


solvfpz
FREEOP

2 months ago

i checked this but yeah i am not able to understand



solvfpz
FREEOP

2 months ago

now all good?

1454084930198962400


solvfpz
FREEOP

2 months ago

ig yeah


Delete that photo now


You just leaked your token


solvfpz
FREEOP

2 months ago

lol no


solvfpz
FREEOP

2 months ago

i am testing


But yes, redeploy your service.


solvfpz
FREEOP

2 months ago

done


solvfpz
FREEOP

2 months ago

now working


solvfpz
FREEOP

2 months ago

@pepper btw we can redepoly project unlimited time ?



solvfpz
FREEOP

2 months ago

ok


solvfpz
FREEOP

2 months ago

@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


solvfpz
FREEOP

2 months ago

but after hosting bot in railway its not working


solvfpz
FREEOP

2 months ago

@pepper


cicerorph
HOBBY

2 months ago

Could you send the error?


solvfpz
FREEOP

2 months ago


cicerorph
HOBBY

2 months ago

You sent the DISCORD_TOKEN env log.


solvfpz
FREEOP

2 months ago

`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)`


solvfpz
FREEOP

2 months ago

check this code


solvfpz
FREEOP

2 months ago

whats the problem


cicerorph
HOBBY

2 months ago

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.


cicerorph
HOBBY

2 months ago

About the DISCORD_TOKEN env variable error, just follow what was sent upwards.


solvfpz
FREEOP

2 months ago

⚠️ Could not fetch LTC price, try again later.


solvfpz
FREEOP

2 months ago

i am not able to understand what is going on


solvfpz
FREEOP

2 months ago

Error fetching LTC price: 'price'


solvfpz
FREEOP

2 months ago

@Mubi

1454110281503474000


cicerorph
HOBBY

2 months ago

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}")

cicerorph
HOBBY

2 months ago

To understand it first you need to get what was the error.


domehane
FREE

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)

solvfpz
FREEOP

2 months ago

ok


solvfpz
FREEOP

2 months ago

@Mubi

1454112143615066400


cicerorph
HOBBY

2 months ago

Binance blocks requests from datacenters and other hosting providers


cicerorph
HOBBY

2 months ago

It worked on your local machine because it's an actual real user network.


cicerorph
HOBBY

2 months ago

(You shouldn't scrape websites for info like Binance)


solvfpz
FREEOP

2 months ago

okay


cicerorph
HOBBY

2 months ago

Try to find an API on the internet so you can get info


solvfpz
FREEOP

2 months ago

yeah i am using Coinbase Public API now


Status changed to Solved brody about 2 months ago


solvfpz
FREEOP

2 months ago

@Mubi @pepper railyway is free for only 30 days?


The trial lasts for 30 days or when you use up $5 worth of credits.


solvfpz
FREEOP

2 months ago

ok


Loading...