R
Railway•9mo 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•9mo ago
Project ID: e973bf7d-52cf-4a8e-b30c-0829b7914a35
lostkey
lostkeyOP•9mo ago
e973bf7d-52cf-4a8e-b30c-0829b7914a35 when running locally this does not happen
Brody
Brody•9mo 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
lostkeyOP•9mo ago
ahh shucklebutts 😠 yea im like running an sqlite db
Brody
Brody•9mo ago
same goes for that, you would need to store that sqlite database file in a volume
lostkey
lostkeyOP•9mo ago
alright perfect ill see if that works and get back hold on
Brody
Brody•9mo ago
sounds good
lostkey
lostkeyOP•9mo 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•9mo ago
thats correct
lostkey
lostkeyOP•9mo ago
alr\ @Brody i love you your a beautiful man
Brody
Brody•9mo ago
lol thanks
lostkey
lostkeyOP•9mo ago
got everything working
Brody
Brody•9mo ago
awsome, that was fast
lostkey
lostkeyOP•9mo ago
ok wait one more question if i push something from the github repo will it maintain the volume no matter what
Brody
Brody•9mo ago
yes, unless you have done something wrong, like accidently wrote code that deleted files in the volume
lostkey
lostkeyOP•9mo ago
alright perfect ty, you've been like genuinely sm help
Brody
Brody•9mo ago
happy to help 🙂
lostkey
lostkeyOP•9mo 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•9mo 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
lostkeyOP•9mo ago
thats the weird part its just not running like hold on
Brody
Brody•9mo ago
code issue then, but without any sort of logs there not too much I can help with
lostkey
lostkeyOP•9mo ago
It runs whenever i dont host it on here and logs properly
Brody
Brody•9mo ago
unfortunately that doesn't mean it's not a code issue what's your volumes mount point
lostkey
lostkeyOP•9mo ago
a folder with everything i need volumeifieid i did a silly and i think i fucked it up
Brody
Brody•9mo ago
you aren't making much sense tbh
lostkey
lostkeyOP•9mo 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•9mo 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
lostkeyOP•9mo 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•9mo 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
lostkeyOP•9mo ago
yea no i get that fs
Brody
Brody•9mo ago
so the database in the volume would be a fresh empty database, unless your app is capable of importing data to it?
lostkey
lostkeyOP•9mo ago
well yes, but it should persist the changes i do to it
Brody
Brody•9mo ago
how are you doing "the changes"
lostkey
lostkeyOP•9mo ago
as in adding/removing ?
Brody
Brody•9mo ago
anything, how do you think you are making changes to the database
lostkey
lostkeyOP•9mo 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•9mo 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
lostkeyOP•9mo ago
i probably am sounding very slow rn but i am so lost
Brody
Brody•9mo 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
lostkeyOP•9mo 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•9mo ago
what is the volumes mount point
lostkey
lostkeyOP•9mo ago
No description
Brody
Brody•9mo ago
show me the code that opens the sqlite database
lostkey
lostkeyOP•9mo 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•9mo ago
sorry but that's not at all what I asked for
lostkey
lostkeyOP•9mo 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•9mo ago
nixpacks or dockerfile?
lostkey
lostkeyOP•9mo ago
nixpacks
Brody
Brody•9mo ago
then your mount point is wrong it should be /app/assets
lostkey
lostkeyOP•9mo ago
uh okay hold on ill try that
lostkey
lostkeyOP•9mo ago
uhh idk i dont think so
Brody
Brody•9mo ago
your mount point is wrong, please read the docs I linked
lostkey
lostkeyOP•9mo ago
it's not locating anything in the volume when i call it using the updated mountpoint
Brody
Brody•9mo 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
lostkeyOP•9mo ago
so.. what do i do? how do i make the assets folder.. not empty 😭
Brody
Brody•9mo ago
mount the volume somewhere else like /app/data then access the database from data/data.sqlite
lostkey
lostkeyOP•9mo ago
so every time i call something from the original folder i have to add /app infront of it
Brody
Brody•9mo ago
no
lostkey
lostkeyOP•9mo ago
because the db is not the only thing in a volume, so im confused
Brody
Brody•9mo ago
what else do you think is in the volume?
lostkey
lostkeyOP•9mo ago
all of these is what i have persisting in the volume
No description
lostkey
lostkeyOP•9mo ago
i want*
Brody
Brody•9mo 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
lostkeyOP•9mo ago
i am 😭
Brody
Brody•9mo ago
do this please
lostkey
lostkeyOP•9mo ago
ok now im getting errors about no tables in the sqlite db
Brody
Brody•9mo ago
yes because it's an empty database empty volume, empty database
lostkey
lostkeyOP•9mo ago
ok
Brody
Brody•9mo ago
it would be must simpler to just use postgres
lostkey
lostkeyOP•9mo 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•9mo ago
yes, empty volume, empty database you can pre load stuff into the volume but it's not straightforward
lostkey
lostkeyOP•9mo ago
ok, is there documentation for that
Brody
Brody•9mo 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
lostkeyOP•9mo ago
ah ok ill come back in a bit i need a nap tysm
Want results from more Discord servers?
Add your server