0

Hello I hosted my discord.py bot on heroku and its working as expected. The poblem is that I have sqlite3 file in my github repo and its able to read the data. but I am not able to write to it.

below is my code to add data to the file.

async def itemadd(ctx, name, item):
if ctx.message.author.guild_permissions.administrator:
    table ="CREATE TABLE IF NOT EXISTS {}(CODE VARCHAR(255))".format(name.title())
    cursor.execute(table)
    cursor.execute("INSERT INTO {} VALUES (?)".format(name.title()), (item,))
    db.commit()

else:
    embed = discord.Embed(title="You do not have administrator permission to use this command", description=ctx.author.mention, color=0xff5555)       
    await ctx.send(embed=embed)

Thanks in advance :)

Joshua
  • 249
  • 4
  • 16

1 Answers1

1

That's not how it works. Heroku's filesystem is ephemeral, which means any changes you make to your file will be reverted every once in a while.

You should move your SQL database to either heroku's Postgresql service (free but limited) or connect to a different database provider.

Here's the link for the heroku's add-on https://elements.heroku.com/addons/heroku-postgresql

One alternative provider https://www.elephantsql.com/plans.html

Also, i believe your SQL query might be susceptible to injection. Consider reading this question: Is this Python code vulnerable to SQL injection? (SQLite3)

ChrisDewa
  • 642
  • 4
  • 11