R
Railway•3mo ago
lostkey

Using discord bot with railway

I'm running a discord bot off a github repo, however i feel like the issue is that since it's pushing off the github repository it's only updating changes locally. so whenevever settings change via the bot in json files or things like that which would normally save i dont think its quite working the way it should, any help would be cool
75 Replies
Percy
Percy•3mo ago
Project ID: e973bf7d-52cf-4a8e-b30c-0829b7914a35
lostkey
lostkey•3mo ago
e973bf7d-52cf-4a8e-b30c-0829b7914a35 when running locally this does not happen
Brody
Brody•3mo ago
you would want to store those json files in a volume https://docs.railway.app/guides/volumes otherwise changes to those json files that are made wont persist between deployments. or in the most ideal scenario, use a database like postgres.
lostkey
lostkey•3mo ago
ahh shucklebutts 😠 yea im like running an sqlite db
Brody
Brody•3mo ago
same goes for that, you would need to store that sqlite database file in a volume
lostkey
lostkey•3mo ago
alright perfect ill see if that works and get back hold on
Brody
Brody•3mo ago
sounds good
lostkey
lostkey•3mo ago
ok i feel like im tripping i added one for the json but now hte option is no longer popping up does that mean i can only have one vol
Brody
Brody•3mo ago
thats correct
lostkey
lostkey•3mo ago
alr\ @Brody i love you your a beautiful man
Brody
Brody•3mo ago
lol thanks
lostkey
lostkey•3mo ago
got everything working
Brody
Brody•3mo ago
awsome, that was fast
lostkey
lostkey•3mo ago
ok wait one more question if i push something from the github repo will it maintain the volume no matter what
Brody
Brody•3mo ago
yes, unless you have done something wrong, like accidently wrote code that deleted files in the volume
lostkey
lostkey•3mo ago
alright perfect ty, you've been like genuinely sm help
Brody
Brody•3mo ago
happy to help 🙂
lostkey
lostkey•3mo ago
@Brody hello im back i need you the bot is running, and it's checking through a script to see if a userid is in the sqlite db if it isnt it adds it if it is it resumes code that works fine however i think the issue is that since the script is checking a volume and the script isnt it the volume, its bugging out am i crazy second question can i just put everything in a volume
Brody
Brody•3mo ago
the script not being in the same location as the database would pose no real issues provided everything was done right, so please show any errors you are getting not quite how it works
lostkey
lostkey•3mo ago
thats the weird part its just not running like hold on
Brody
Brody•3mo ago
code issue then, but without any sort of logs there not too much I can help with
lostkey
lostkey•3mo ago
It runs whenever i dont host it on here and logs properly
Brody
Brody•3mo ago
unfortunately that doesn't mean it's not a code issue what's your volumes mount point
lostkey
lostkey•3mo ago
a folder with everything i need volumeifieid i did a silly and i think i fucked it up
Brody
Brody•3mo ago
you aren't making much sense tbh
lostkey
lostkey•3mo ago
yea i know sorry im just like running off a few hours of sleep give me like 1 sec Okay sorry, so essentially i'm running a currency manager bot of railway. Whenever you want to add/give currency, it checks an sqlite db thats in the vol to see if the userid is there, if not it'll add the userid + the currency. however when i run it on railway, it just does nothing if it detects the user isnt in the sqlite db i was wondering if this has anything to do with volumes or is just a code issue
Brody
Brody•3mo ago
how do you know that the user is in the database? you created an empty volume and then your code would have created an empty database because one didn't exist
lostkey
lostkey•3mo ago
it turns the the target's @ into a userid and checks the entire thingy to see if it matches anything in the userid column
Brody
Brody•3mo ago
I'm not quite sure if that answers my question if you are expecting the sqlite database in the volume to be the same as the one in github you are mistaken
lostkey
lostkey•3mo ago
yea no i get that fs
Brody
Brody•3mo ago
so the database in the volume would be a fresh empty database, unless your app is capable of importing data to it?
lostkey
lostkey•3mo ago
well yes, but it should persist the changes i do to it
Brody
Brody•3mo ago
how are you doing "the changes"
lostkey
lostkey•3mo ago
as in adding/removing ?
Brody
Brody•3mo ago
anything, how do you think you are making changes to the database
lostkey
lostkey•3mo ago
datas = await func.DataFetch(self.bot, 'all', 'points', msg.guild.id)
if len(datas) != 0:
for data in datas:
if data[1] == msg.author.id:
AuthorData = data
break
else:
AuthorData = None
if AuthorData:
await func.DataUpdate(self.bot, f"UPDATE points SET points = {AuthorData[2]+POINTS_TO_BE_GIVEN_PER_MESSAGE} WHERE guild_id = {AuthorData[0]} and user_id = {AuthorData[1]}")
else:
await func.DataUpdate(self.bot, f"INSERT INTO points(guild_id, user_id, points) VALUES(?,?,?)", msg.guild.id, msg.author.id, POINTS_TO_BE_GIVEN_PER_MESSAGE)
else:
await func.DataUpdate(self.bot, f"INSERT INTO points(guild_id, user_id, points) VALUES(?,?,?)", msg.guild.id, msg.author.id, POINTS_TO_BE_GIVEN_PER_MESSAGE)
except:
print(traceback.format_exc())
datas = await func.DataFetch(self.bot, 'all', 'points', msg.guild.id)
if len(datas) != 0:
for data in datas:
if data[1] == msg.author.id:
AuthorData = data
break
else:
AuthorData = None
if AuthorData:
await func.DataUpdate(self.bot, f"UPDATE points SET points = {AuthorData[2]+POINTS_TO_BE_GIVEN_PER_MESSAGE} WHERE guild_id = {AuthorData[0]} and user_id = {AuthorData[1]}")
else:
await func.DataUpdate(self.bot, f"INSERT INTO points(guild_id, user_id, points) VALUES(?,?,?)", msg.guild.id, msg.author.id, POINTS_TO_BE_GIVEN_PER_MESSAGE)
else:
await func.DataUpdate(self.bot, f"INSERT INTO points(guild_id, user_id, points) VALUES(?,?,?)", msg.guild.id, msg.author.id, POINTS_TO_BE_GIVEN_PER_MESSAGE)
except:
print(traceback.format_exc())
if thats what your asking for
Brody
Brody•3mo ago
not really, I'm asking for a more broad overview, because right now it seems like you're just interacting with an empty database
lostkey
lostkey•3mo ago
i probably am sounding very slow rn but i am so lost
Brody
Brody•3mo ago
or you aren't interacting with a database on the volume at all, because you have gotten your paths incorrect what is the volumes mount point
lostkey
lostkey•3mo ago
well no its /assets which is where the db, the functions that assist the db and anything else that needs to be in a volume is whenever a id that is already in the sqlite db is pulled it works perfectly
Brody
Brody•3mo ago
what is the volumes mount point
lostkey
lostkey•3mo ago
No description
Brody
Brody•3mo ago
show me the code that opens the sqlite database
lostkey
lostkey•3mo ago
ok
datas = await func.DataFetch(self.bot, 'all', 'points', msg.guild.id)
if len(datas) != 0:
for data in datas:
if data[1] == msg.author.id:
AuthorData = data
break
else:
AuthorData = None
if AuthorData:
await func.DataUpdate(self.bot, f"UPDATE points SET points = {AuthorData[2]+POINTS_TO_BE_GIVEN_PER_MESSAGE} WHERE guild_id = {AuthorData[0]} and user_id = {AuthorData[1]}")
else:
await func.DataUpdate(self.bot, f"INSERT INTO points(guild_id, user_id, points) VALUES(?,?,?)", msg.guild.id, msg.author.id, POINTS_TO_BE_GIVEN_PER_MESSAGE)
else:
await func.DataUpdate(self.bot, f"INSERT INTO points(guild_id, user_id, points) VALUES(?,?,?)", msg.guild.id, msg.author.id, POINTS_TO_BE_GIVEN_PER_MESSAGE)
except:
print(traceback.format_exc())
datas = await func.DataFetch(self.bot, 'all', 'points', msg.guild.id)
if len(datas) != 0:
for data in datas:
if data[1] == msg.author.id:
AuthorData = data
break
else:
AuthorData = None
if AuthorData:
await func.DataUpdate(self.bot, f"UPDATE points SET points = {AuthorData[2]+POINTS_TO_BE_GIVEN_PER_MESSAGE} WHERE guild_id = {AuthorData[0]} and user_id = {AuthorData[1]}")
else:
await func.DataUpdate(self.bot, f"INSERT INTO points(guild_id, user_id, points) VALUES(?,?,?)", msg.guild.id, msg.author.id, POINTS_TO_BE_GIVEN_PER_MESSAGE)
else:
await func.DataUpdate(self.bot, f"INSERT INTO points(guild_id, user_id, points) VALUES(?,?,?)", msg.guild.id, msg.author.id, POINTS_TO_BE_GIVEN_PER_MESSAGE)
except:
print(traceback.format_exc())
async def DataFetch(bot, command, table, *vals):
try:
# There is no use for bot parameter in Sqlite3 but on migration to cloud database like postgresql, you will need it.
query = f"SELECT * FROM {table}"
if len(vals) == 1:
query += f' WHERE guild_id = {vals[0]}'
elif len(vals) == 2:
query += f' WHERE guild_id = {vals[0]} and user_id = {vals[1]}'
else:
pass
cursor.execute(query)
if command == 'all':
return cursor.fetchall()
else:
return cursor.fetchone()
except:
print(traceback.format_exc())

async def DataUpdate(bot, query, *vals):
if len(vals) == 0:
cursor.execute(query)
else:
cursor.execute(query, vals)
db.commit()
async def DataFetch(bot, command, table, *vals):
try:
# There is no use for bot parameter in Sqlite3 but on migration to cloud database like postgresql, you will need it.
query = f"SELECT * FROM {table}"
if len(vals) == 1:
query += f' WHERE guild_id = {vals[0]}'
elif len(vals) == 2:
query += f' WHERE guild_id = {vals[0]} and user_id = {vals[1]}'
else:
pass
cursor.execute(query)
if command == 'all':
return cursor.fetchall()
else:
return cursor.fetchone()
except:
print(traceback.format_exc())

async def DataUpdate(bot, query, *vals):
if len(vals) == 0:
cursor.execute(query)
else:
cursor.execute(query, vals)
db.commit()
Brody
Brody•3mo ago
sorry but that's not at all what I asked for
lostkey
lostkey•3mo ago
oh my god yea sorry hold on
db = sqlite3.connect('assets/data.sqlite')
cursor = db.cursor()
db = sqlite3.connect('assets/data.sqlite')
cursor = db.cursor()
Brody
Brody•3mo ago
nixpacks or dockerfile?
lostkey
lostkey•3mo ago
nixpacks
Brody
Brody•3mo ago
then your mount point is wrong it should be /app/assets
lostkey
lostkey•3mo ago
uh okay hold on ill try that
lostkey
lostkey•3mo ago
uhh idk i dont think so
Brody
Brody•3mo ago
your mount point is wrong, please read the docs I linked
lostkey
lostkey•3mo ago
it's not locating anything in the volume when i call it using the updated mountpoint
Brody
Brody•3mo ago
the volume is empty, therefore the assets folder is now going to be empty your database being stored in the assets folder is not ideal anyway, it should be stored in a separate more applicably named folder
lostkey
lostkey•3mo ago
so.. what do i do? how do i make the assets folder.. not empty 😭
Brody
Brody•3mo ago
mount the volume somewhere else like /app/data then access the database from data/data.sqlite
lostkey
lostkey•3mo ago
so every time i call something from the original folder i have to add /app infront of it
Brody
Brody•3mo ago
no
lostkey
lostkey•3mo ago
because the db is not the only thing in a volume, so im confused
Brody
Brody•3mo ago
what else do you think is in the volume?
lostkey
lostkey•3mo ago
all of these is what i have persisting in the volume
No description
lostkey
lostkey•3mo ago
i want*
Brody
Brody•3mo ago
none of those files are in the volume, what makes you say that i think you may be misunderstanding the concept of a volume
lostkey
lostkey•3mo ago
i am 😭
Brody
Brody•3mo ago
do this please
lostkey
lostkey•3mo ago
ok now im getting errors about no tables in the sqlite db
Brody
Brody•3mo ago
yes because it's an empty database empty volume, empty database
lostkey
lostkey•3mo ago
ok
Brody
Brody•3mo ago
it would be must simpler to just use postgres
lostkey
lostkey•3mo ago
im not sure how to use that so with volumes to be sure, when i put it in a volume its gonna start off empty no matter what
Brody
Brody•3mo ago
yes, empty volume, empty database you can pre load stuff into the volume but it's not straightforward
lostkey
lostkey•3mo ago
ok, is there documentation for that
Brody
Brody•3mo ago
no it's more so I tell you how to do it, but I would like to avoid that if possible, and instead ask you to abandon sqlite and use postgres or mysql
lostkey
lostkey•3mo ago
ah ok ill come back in a bit i need a nap tysm
Want results from more Discord servers?
Add your server
More Posts
Error: lost connection with pg db (node, express)Hello folks, I’ve deployed a Node.js app with Express on Railway. Everything works fine, but every d"Application failed to respond", but server appears to be alive and wellToday around noon Eastern our production server started serving Railway's 'app unavailable' error. WRailway routing problems?Looked in incidents but nothing there. My railway deployment is routing to "Application failed to rHow can I access to the SLL certificate file? My app config requires itI have a bun app, that seems to require the full path to a certificate. Where could I get that ? ThUrgent: Prisma cannot find the required `libssl`My site just went down. I am having the same problem as this https://discord.com/channels/7135033453Can i temporarily remove my MySQL Database without deleting it completely?I want to perform this because I am running out of credits and I am also not using the DataBase in rusage based pricingPlease help me understand how a project on railway with 0 usage (no calls to the server or DB) for aHelp with setup of laravel cmds on project deploymentHello everyone so im hosting a laravel rest api but i cant seem to access the terminal and run cmds Postgres Database private url, is it faster and how to use it?I have a Django rest framework setup with postgress db and it seems the connection is slow. I noticumami deployment fails since migration of railwayHi there, I hope you can help me. I am not too well with backend (database, docker, etc) programmin