#databases
1 messages · Page 101 of 1
and in your main: from database import database
ogey
no idea, google it
Not even google knows
¯_(ツ)_/¯
from cogs.database import database heh it was just this
found it on stack overflow
@tough needle I've got somewhere
Now a whole new
issue
yay
Traceback (most recent call last):
File "C:\UsersAppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File ", line 191, in add_coins
database.add_coins_db(user_id, added_coins)
File , line 17, in add_coins_db
cursor.execute("""
sqlite3.OperationalError: no such table: users
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\UserppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\UsersAppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\UsersppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: no such table: users```
Read the error
I did
it cant find the table
but there is a table
heh
the other things are going to be other shit im going to work on once this is done
@tough needle Is there something really obvious that im missing here or
I'm gonna copy a message link here because its 4 am where I am so im gonna go to bed if you've got any idea to the stuff that happened above then just @ me and i'll take a read
hi i was wondering if someone would be able to assist with mongodb update query
ask away
im trying to update my dictionary nested inside an array in my mongo Collection for a rest api. I'm tryin gto query and evaluate if the name matches, then update the collection fields with the new info. I can't seem to get it to work, it just returnss True without modifying.
-Tried dot notation, commented out, same result
-Tried using array_filter, kept claiming it's undefined
def put(self, user_name):
#sample incoming object
item = {"name": "oranges", "category": "TEST", "purchase_date": "11/21/20", "expiration_date": "12/04/20", "count": 5}
item_name = item["name"]
item_category = item['category']
item_purchase_date = item["purchase_date"]
item_expiration_date = item["expiration_date"]
lookup = collection.find_one({"user_name": user_name})
db_item = lookup.get('user_items')
#Try just updating item_category first
for index, entry in enumerate(db_item):
name = json.loads(entry).get("name")
if name == item_name:
# collection.update_one({"user_name.user_items":item_name},
# {"$set": {"user_name.$.category": item_category})
collection.update_one({"user_name.user_items": item_name},
{"$set": {"category": item_category}})
return True```
I'm not very familiar with MongoDb, so I might be wrong here, but you've used user_names.user_items, but user_items doesn't seem to be nested inside user_names
They seem to be on the same level
does it have to be nested to use the dot notation?
yes, that's what the dot notation indicates, it is used to access child elements
working in postgresql/python, I've written this statement which successfully runs to update many rows at once using psycopg2,
"UPDATE daily_data SET "
"active_seconds=data.active_seconds + daily_data.active_seconds, "
"inactive_seconds=data.inactive_seconds + daily_data.inactive_seconds "
"FROM (VALUES %s) "
"AS data (active_seconds, inactive_seconds, streamer_id, viewer_id, date, game)"
"WHERE "
"streamer_id=data.streamer_id AND "
"viewer_id=data.viewer_id AND "
"date=data.date AND "
"game=data.game"```
I've got a second statement
"UPDATE viewer_data SET "
"honor=data.honor + viewer_data.honor "
"FROM (VALUES %s) "
"AS data (honor, streamer_id, viewer_id)"
"WHERE "
"streamer_id=data.streamer_id AND "
"viewer_id=data.viewer_id"```
which is throwing an error
psycopg2.errors.AmbiguousColumn: column reference "streamer_id" is ambiguous
LINE 1: ...37)) AS data (honor, streamer_id, viewer_id)WHERE streamer_i...
I've asked a couple other people and have been looking at this for a while now and both I and others (in SWE) are not seeing the issue, any help?
@ me if you respond please in case I don't see immediately
Always specify the table you're using
In your WHEREs you dont
Hence ambiguity hence error
I've changed the query I was working on to just get the results from those two tables separately. Now the question - is it more efficient to filter the subqueries separately, or apply WHERE to the resulting table t?
SELECT
emote,
sum(msg_count) as message_count,
sum(rct_count) as reaction_count,
sum(msg_count) + sum(rct_count) as total_count
FROM (
SELECT
emote,
period,
guild_id,
count AS msg_count,
0 AS rct_count
FROM emotes
> WHERE guild_id = 1 AND
> period > '2020-07-01'
UNION ALL
SELECT
emote,
period,
guild_id,
0 AS msg_count,
count AS rct_count
FROM reactions
> WHERE guild_id = 1 AND
> period > '2020-07-01'
) AS t
>WHERE guild_id = 1 AND
>period > '2020-07-01'
GROUP BY emote
ORDER BY total_count DESC```
thank you, got it down now
Hey guys, Using SQLalchemy relationships
something like,
session.query(User). \
options(sqlalchemy.orm.joinedload(User.Addresses)). \
order_by(User.firstseen.desc()). \
limit(limit). \
all()
How do i specify how many addresses to return?
I'm trying to send a simple search request to ES but I'm getting all these errors: https://bpa.st/Z52Q
and each block of errors ends with "ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)"
@blazing void That returns 10 users, but if there was 20 addresses it would still return 20 of them all as address objects.
oh I see, you have a joinedload
have you tried doing a regular join?
is Addresses a table? if your relations are set up correctly, you should be able to query(User, Address) or query(User).join(Address)
or in fact... if your Addresses are relations, do you even need the join?
Ths works but its limited the amount of users it returns, but doesn't limit the amount of rows returns from host_snapshots.
I get 24 snapshots a day, so for each host if I just wanted to display 24 hours worth of data, I would only need the last 24 snapshots
As you can see, 13 snapshot objects, when i'm trying to limit it 🙂
Um, ultimately could be looking at 200-300 hosts. if not more 😂
future proof would be 10k.
but would limit queries to 500 ish
I'm not sure there's an easy way to do the joinedLoad, but I think doing the join with query(Host, Whatever) or query(Host).join(Whatever) should get you your data without lazy loading
but also 10k entries in a database isn't much, but I do agree resolving 500 relations lazily would be slow
especially if I have a years worth of host_snapshots it's trying to load per host!
Brains not working
@blazing void found https://docs.sqlalchemy.org/en/13/orm/join_conditions.html#row-limited-relationships-with-window-functions in the docs.. too tired to know how to use lol
I need help on setting up aiosqlite
Nvm
So, I am trying to delete data from a sqlite database, using DELETE FROM <table> WHERE <condition> does not work, but DELETE FROM <table> works, could you please help me figure this out?
A mre with pytest test and output can be found here https://hatebin.com/zptehnikcg, please let me know if I forgot anything for the mre.
I am aware I should be using the ? notation to pass arguments to the queries, I will fix that as soon as it is apropriate
Your condition is probably wrong
^
Try the exact same condition with a select and see what it returns
let me recheck, I checked it before some times, but I will try that select method
Hey, I want to use aiosqlite to make a operation system for my discord bot. When someone does the command !create_op OperationNameHere it's going to create a text channel (already coded that) and then log the operation in the database. E.x that it logs what they named the channel to.
I will jump back to #discord-bots to make another command and then I guess come back here to log that thing too.
Anywho, my question is how do I connect to the aiosqlite database, how do I make a table, and how do I insert & print out the data?
async def addreason(self, ctx, punishment_id: str, *, reason: str):
query = "UPDATE moderation SET warning=" + reason + " WHERE punishmentID=" + punishment_id
cursor.execute(query)
db.commit()
For some reason this SQL query won't execute, nothing after it will run so thats what I'm assuming, no errors are returned either.
yep it is wrong, thank you for making me see it 😂
My guess would be that id is an int, not a string
indeed it is, but taking the '' does not change the output
how would I change it to an ID?
int(punishment_id)
Ah so an int
but the SQL query would fail if I parsed and int, surely?
Yeah it expects a string.
by default it is a string
both are
ok I cannot figure this out...
Are you sure you have something in there with an id of 0 ? IDs usually start at 1 in databases @torn sphinx
1s, I will send prints.
these are the tables
And here's the relevant part of the test
db_man = DBManager(':memory:', schema=schema)
c = Class(db_man, "a", 8, 1)
e = Evaluation(db_man, class_id=c.get_primary_key()[1], weight=0.30, eval_id=-1)
print(db_man.fetch_all_table(e))
print(db_man.fetch_all_table(c))
assert db_man.get_table_size('evaluations') == 1
assert db_man.get_table_size('classes') == 1
print("------------------------")
e.remove()
print(db_man.fetch_all_table(e))
print(db_man.fetch_all_table(c))
assert db_man.get_table_size('evaluations') == 0 # ERROR
assert db_man.get_table_size('classes') == 1
oh wait
nah nvm, could be some error on the schema but I don't think so. here it is: https://hatebin.com/jmcijpores
Can you print a SELECT id FROM 'evaluations' ?
Well that's weird
any clue on anything I should look for?
I placed that select both before and after the deletion, same result
I have no idea sorry, especially since SQL is my weak spot :/
understandable, thank you for the help
Does anyone have any suggestions for db's other than sqlite3 to be used for a discord bot
Im not really liking sqlite3
soo
mysql maybe?
something is wrong with my db browser sqlite
so when i edit the table data in manual it gives me database is locked error
i have an issue, i'm trying to get a price of a certain product and do a calculation with that price. but when i try to do a calculation with the result, it says builtins.TypeError: 'int' object is not subscriptable. Does anyone know what i'm doing wrong?
if price:
amount = int(input('hoe veel wil je? (stenen zijn gerekend in m2 ) \n'))
for i in price: #error happens here
total = amount * i[1]
return product, total #till here
that's my code^. PC stands for product code
it's telling you i is not a string, list, or dictionary, or anything else that would allow you to do i[1]
also your code appears to be overwriting total for every thing inside the structure price, there is something wrong with your code beyond just syntax
oh ok.... sorry, i'm still new at programming
oh yeah, no worries, just letting you know once you fix i[1] problem you'll need to look at hat's going on with total = inside a for loop
you were right! solved it, thanks!!
k = await _bot.pg_con.fetchrow("""SELECT im FROM test WHERE name = 'kek'""")
with open('test.gif', 'wb') as f:
f.write(k)```
if you open test.gif as binary, then f.write() expects bytes-like
what you're passing it is an asyncpg.Record, you need to read the field from it
presumably im
I have the bytes in im and im is a bytea typw colums
you need to get the image from the record object
Okay
How to get the image from record object ?
y = k["im"] ? Amd write y ?
It worked but i m struggling to send test.gif
wdym
k = await _bot.pg_con.fetchrow("""SELECT im FROM test WHERE name = 'kek'""")
with open('test.gif', 'wb') as f:
f.write(k["im"])
How do i send the test.gif file now ?
could anyone teach me how to use PostgreSQL? i've tried reading the toutorials and dont really understand. I'm just trying to basicly have a dictionary where i can retrieve a large list given an integer
ping me if you can help ty in advance
Wdym, why are you writing to a file if you just want to send the data in that file somewhere
use sockets probably
how would i use sockets?
.ojsk py
k = await _bot.pg_con.fetchrow("""SELECT im FROM test WHERE name = 'kek'""")
#getting the bytes data
file = discord.File (k["im"])
#bytes data ^
await ctx.send(file = file)
#sending it```
was test.gif a valid image when you wrote it
the error is on the line file gets declared so
was test.gif a valid image when you wrote it
@normal igloo
Yes, but when you did write it was it a valid image
was getting the same error
do print(type(k["im"]))
This is working fine
<class 'bytes'>
do
print(type(k["im"]))
^^
It does takes it as a bytes object
No it doesn't
"fp
A file-like object opened in binary mode and read mode or a filename representing a file in the hard drive to open."
"Note If the file-like object passed is opened via open then the modes ‘rb’ should be used.
To pass binary data, consider usage of io.BytesIO."
Oh
So how do i ? Send the text.gif ?
k = await _bot.pg_con.fetchrow("""SELECT im FROM test WHERE name = 'kek'""")
with open('test.gif', 'wb') as f:
f.write(k["im"])
type(k["im"])```
> <class 'bytes'>
k = await _bot.pg_con.fetchrow("""SELECT im FROM test WHERE name = 'kek'""")
#getting the bytes data
file = discord.File (k["im"])
#bytes data ^
await ctx.send(file = file)
#sending it
> Null bytes error
How do i send that gif
"To pass binary data, consider usage of io.BytesIO.""
if I have a massive basically undownloadable table in Access (can't import to Excel), can I use pyodbc to pull that data into Python to be manipulated or printed out?
I'm trying to find use cases for Python in my workplace and I feel like manipulating data from our HUGE access tables would be a good start
depending on the type of data, maybe even pandas would be more appropriate
pandas' read_sql_query will accept a connection via pyodbc
You can use pyodbc for that. I've found it useful for pulling out data from old access tables and then using pandas to manipulate it for data analysis. I usually also end up re-storing it into something like sqlite3 since it's a flat file db.
So my data updates every night at 3 AM, and I'd like to more pull information based on certain filters... So, it's not really 'data analysis' so much as it's like "If we have less than a month of inventory on hand on the refresh today, pull it out and send to the purchasing team' and things like that
I guess realistically I can just create an Access report that does that work?
so you want ETL to run at shortly after 3 AM to do some stuff
More or less yes (after googling what ETL is :))
I use Apache Airflow for ETL, it's written in Python, but I don't recommend that for starting with, it's a bit of a pain to set up and doesn't feel "modern"
but anyway, sounds like if your data is in Access, try fetching the data via pyodbc first; then try getting the data into Pandas next, which'll let you easily modify it
OK, I wanted to make sure I wasn't using a $10,000 hammer to slam in a $.01 nail by using Python/Pandas if you know what I mean
Thanks for the help guys!
sure sure, Pandas is very good for this, you can basically treat it like a programmer's excel
(and good investment in skills if you need to do more data-sciency things later)
Yes! That's what I'm hoping for. Using it to get comfortable with Pandas while doing more 'simple' tasks and then move forward from there
hey! how do I create a database for my game?
if anyone answers this please ping me
im trying to learn how to do database
can someone help me or refer me to a good video series that explains how to do get started?
Ignoring exception in command game start:
Traceback (most recent call last):
File "C:\Users\csuser\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\csuser\Desktop\KAITOU JOKER\start_game.py", line 87, in start
await cursor.execute(sql, (ctx.author.id, str(greentick)))
AttributeError: '_LazyloadContextManager' object has no attribute 'execute'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\csuser\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\csuser\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 1234, in invoke
await ctx.invoked_subcommand.invoke(ctx)
File "C:\Users\csuser\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\csuser\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: '_LazyloadContextManager' object has no attribute 'execute'
anyone helping me?
PLS ANOYONE?
Pasting large amounts of code
If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pydis.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
Here click this link copy paste code press save and send us the link
An example of an asynchronous database of this sqlite3 on Github or something else
@tender coral ?
I asked if you can send full code
Because just the error isnt enough
I sent a website where you can paste the cose
@tender coral full code of the command?
@game.command()
async def start(self, ctx):
if await is_unlocked(ctx.author, self.bot):
pass
if not await is_unlocked(ctx.author, self.bot):
if not await in_game(ctx.author, self.bot):
greentick = self.bot.get_emoji(731565652250460181)
embed = discord.Embed(description=f'Please watch the gif and when you are ready react to {greentick}', color=0xffffe3)
embed.set_image(url='https://images-ext-1.discordapp.net/external/2MuBkRl-BOKfTZtJ0qLRm1IioNxQm3c3lRRmnfrKFLI/https/im2.ezgif.com/tmp/ezgif-2-63d1e669fcfd.gif')
introduction = await ctx.send(embed=embed)
await introduction.add_reaction(greentick)
cursor = self.bot.db.cursor()
sql = 'INSERT INTO wait_for_emoji (user_id, emoji) VALUES (?, ?)'
await cursor.execute(sql, (ctx.author.id, str(greentick)))
sql = 'INSERT INTO in_the_game (user_id) VALUES (?)'
await cursor.execute(sql, (ctx.author.id,))
def check(r, u):
return r.message.channel == ctx.channel and r.emoji == greentick
await self.bot.wait_for('reaction_add', check=check)
await ctx.send('WORKED')
this isthe full code
Thanks
so will u help me
thats in cog
and the command is the sub command
cursor = self.bot.db.cursor()
sql = 'INSERT INTO wait_for_emoji (user_id, emoji) VALUES (?, ?)'
await cursor.execute(sql, (ctx.author.id, str(greentick)))
``` is the main problem i think
he says that cursor has no attribute execute()
WHAHAAAt
So youre trying to run a function that doesnt exist
@tender coral but
async def in_game(user, bot):
cursor = await bot.db.cursor()
sql = 'SELECT * FROM in_the_game WHERE user_id = ?'
await cursor.execute(sql, (user.id,))
row = await cursor.fetchone()
if row is None:
game = False
else:
game = True
return game
async def waiting_for_emoji(user, bot):
cursor = await bot.db.cursor()
sql = 'SELECT * FROM waiting_for_emoji WHERE user_id = ?'
await cursor.execute(sql, (user.id,))
row = await cursor.fetchone()
if row is None:
waiting = False
else:
waiting = True
return waiting
these works
hmmm
idk self.bot.db.cursor works in other cogs @tender coral
ok, funny question could i have a database in json 😆
for my py bot
Yes you can, but it can also get messy and complicated at times with JSON. Personally I would not recommend it, although you can probably can get away with it for small bots, however for growing/medium to larger bots you should consider using a database since its much cleaner, and will be more efficient on your bot in terms of async as well. @torn sphinx
@tender coral i know how to fix it
that was aiosqlite3 but i forgot to put await from of self.bot.db.cursor() !
damn
def test(limit=10) -> List[Host]:
partition = select([
HostSnapshot,
func.row_number().over(
order_by=HostSnapshot.height, partition_by=HostSnapshot.publickeystring
).label('index')
]).alias()
partitioned_b = aliased(HostSnapshot, partition)
Host.partitioned_bs = sqlalchemy.orm.relationship(
partitioned_b,
primaryjoin=and_(partitioned_b.publickeystring == Host.publickeystring)
)
session = db_session.create_session()
hosts = session.query(Host).options(sqlalchemy.orm.selectinload(Host.partitioned_bs))
return hosts
Hey guys, trying to do a Row-Limited Relationships with Window Functions, but just cant seem to get it to work. can anyone help?
Hello! I'm trying to make a leveling system in my bot and using I'm using postgresql, it seems to give me a random error which is so weird. Basically let me explain how it works and how it doesn't. So when I send a normal message it works perfectly, and when I send a command I get this py Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\Dell\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\client.py", line 312, in _run_event await coro(*args, **kwargs) File "c:\Users\Dell\Desktop\Aidas\Rod\cogs\listeners.py", line 31, in on_message db.xp(message.author.id, "+", server_data[2]) File "c:\Users\Dell\Desktop\Aidas\Rod\utils\essentials\sql.py", line 63, in xp xp = f_data[6] TypeError: 'NoneType' object is not subscriptable I've talked to people in d.py and one of them said it could be a what's the database giving me.
(567321250696003606, 1000, 0, 'none', 0, 0, 29, 100) this is how my table looks like, but it gets to None when ever the message is a command...
so if i have a one to many relationship i need two tables right
the second one has the id of the values in the first
one to many is usually talking about the relationship between two different resources
like if u have a class with a parameter thats a list
yeah, usually you'd store that in a separate table
since relational databases don't traditionally support arrays
thought that's not really true anymore 
but if you're talking about a normalized relational design, yes
but it's easier to talk concretely if you have a use case in mind
how do i check if a record exists in a databse?
using sqlite3
if it is not possible in sqlite3 then where is it possible
SELECT * FROM ______ WHERE condition;
or if you literally just wanna know if it exists
SELECT 1 FROM some_table WHERE condition;
ok thanks
Hey lads, I have a very weird issue
Basically whenever I am trying to connect to the database, the connection just "hangs"
It even happens when I am trying to connect locally
I am using Postgres if it helps
Is there any way to run some diagnostics as to why this might be happening
not really a python question but it sounds like you don't have proper network access
is the database local to where you're connecting from?
Yep, it is on my PC
but it just hangs/freezes when I am entering my credentials and wanting to connect
and you can't connect with psql on the command line either?
Nope, I was using psql to connect
but after entering password and pressing Enter, nothing happens
no error, nothing
what operating system
Windows Server 2016
Weirdest part is that it was working fine like 12 hours ago
but then it just stopped
Basically I can still connect to the DB if I reset my PC, but after like a few mins it stops responding
I tried using PGAdmin, and it gave Connection to the server has been lost error when trying to connect to DB locally
wonder if it's some kind of firewall blocking it
or if the database is being stopped somehow
i'm not too familiar with windows administration though, sorry
Firewall is off, but not sure how it can be stopped either 🤔
definitely you need to solve the local database connection issues before trying python stuff though
Yepp
I looked up PGAdmin help page about that error, and it says the following:
"This error message indicates that the connection attempt has taken longer than the specified threshold; there may be a problem with the connection properties provided on the Server dialog, network connectivity issues, or the server may not be running."
Basically it makes sense because connection just hangs, aka takes longer than supposed to
are there logs you can look at for postgres
not sure, I might google how to
How would I insert datetime.now() into postgresql?
stamp = datetime.now()
name = input('Enter your name: ')
cursor.execute('INSERT INTO Testing (stamp, name) VALUES (%s, %s)',
(stamp, name))
conn.commit()
Because, right now, it pushes me down and spits errors at my face
i need some help with aiopg
ive been working with asyncpg and moved because i was getting infinite hangs
but im not sure how to do .execute equivalent in aiopg
How would I insert datetime.now() into postgresql?
@ancient abyss use current_timestamp
Ah, so just replace datetime.now() with that?
try ```python
name = input('Enter your name: ')
cursor.execute('INSERT INTO Testing (stamp, name) VALUES (%s, %s)',
(current_timestamp, name))
conn.commit()```
or maybe with GETDATE() @ancient abyss
do you have to reconnect to aiopg every time or can you just make one pool and use that?
sry try like this : ```python name = input('Enter your name: ')
cursor.execute('INSERT INTO Testing (stamp, name) VALUES (current_timestamp, {})')
.format(name)
conn.commit()```
@ancient abyss
Oh, never seen it done like that. Alrighty
@client.command()
async def welcome(ctx: commands.Context, channel:discord.TextChannel):
"""Use this to set the custom welcome channel"""
await ctx.send('Registered.')
channel_id = channel.id
guild_id = ctx.guild.id
await ctx.send('Registered 2.')
async with client.pool.acquire() as conn:
await conn.execute("INSERT INTO welcomechannels VALUES ($1, $2);", channel_id, guild_id)
await ctx.send('Registered 3.')|
Registered 3 never gets sent.
And there aren't any errors
So the code gets hung on a specific line.
Hi all - Anyone able to help me find a sample working (simple) program for Influx ?
I've got their sample program but keep hitting errors - just looking for one that isn't 4 years old and that forms a working basis that I can learn from....
@client.command()
async def welcome(ctx: commands.Context, channel:discord.TextChannel):
"""Use this to set the custom welcome channel"""
await ctx.send('Registered.')
channel_id = channel.id
guild_id = ctx.guild.id
data = {}
data['welcomechannels'] = []
data['welcome channels'].append({
'guild_id': guild_id,
'channel_id': channel_id
})
with open('data.json', 'w') as f:
json.dump(data, f)
im trying write a json file using this but none of the data ever gets written
I tried making a data.json file
but it still doesn't work
it seems to hang before it reaches the end
It's crashing but you're probably suppressing the error message
you really shouldn't do that
data['welcomechannels'] = []
data['welcome channels'].append({
space doesn't match, so it's throwing a keyerror
oh
i dont remember supressing errors
ill try this
thank you
damn that was so obvious
i appreciate the help :P
@rich trout I so the bot reached the end of the command sequence
however, I dont see the data in the json file
I have the file in the same folder
well, how are you running the bot?
it runs it through the same folder I think?
you can print(os.getcwd()) to find out where it's putting it for sure
Yep
thats the same directory?
your file will be at C:\users\adi\data.json
the "current working directory" is where file operations happen if you don't specify more exactly
since you're calling python from that directory, that's the "current working directory" even if you're running something from far away
is there a way to specify where to get json and to save json from
like in terms of a more specific directory
You could use the whole path, or you could use cd to change the current directory to make it easier on you
wait so there isnt a way to change where the json file is saved?
I just gave two options for how to do that?
Are you clicking a button to get that terminal, or are you typing python e:\...
yeah
now i see what you mean by working directory
For example, if you want to use rm
it would be weird for rm to look for files in C:\windows\system32 if you typed rm text.txt
yea
cd folder or cd .. are pretty much all you need.. on windows, in powershell (PS C:\ gives that away) probably just fine with cd E:\ to change drives, but the regular terminal wants you to give it \D too, for cd /D E:\
That should work 👍
if i just want to run the main.py file, do i have to do anything
or does the python file automatically navigate the folder it's in
python checks the current directory just like all other well-behaved tools
so, if main.py is under Katchi-bot, python main.py should suffice
yep
i just double click to run it lol
@rich trout this is really weird it still saves to C:\users\adi\data.json
if you're clicking a button labeled "run" or "testing" in vscode, it may be setting the CWD to something different
the print(os.getcwd()) bit I sent will tell you what python thinks the CWD is
lol, it's doing it again
I never got the hang of configuring vscode, so I can't really help with that, but I know it's possible
yea im just gonna double click screw it
<
POG


happy coding
I am gonna go sleeps now
lol
wait
should be straightforwards
b4 u go
i wrote this
with open('data.json') as json_file:
data = json.load(json_file)
for p in data['welcomechannels']:
print('guild_id: ' + p['guild_id'])
print('channel_id: ' + p['channel_id'])
it runs in the same command
but it doesnt print anything
i think there might be an error?
I don't see anything obviously wrong
so I'd look into your command error handler to make sure it prints exceptions
By default they just show up in the terminal, I think there's a beginning step most people do that ends up hiding them
It'd be named on_command_error
OH
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.BadArgument):
await ctx.send('I could not find that member...')
if isinstance(error, commands.MissingPermissions):
await ctx.send('You are missing permissions to access that command.')
Bruh moment
i made a custom error handler
imma deleet
concatenation
i figured it out
oh, guild_id was an int wasn't it
derp
I shoulda seen that
but, glad you've got a handle on both of them now
well thanks for all the help @rich trout i appreciate it all
ive been trying database stuff but apparently theres a bug in asyncio
oh?
what bug?
yea theres a error that gets thrown with you're doing loops
I have this code:
import os
import time
import asyncio
async def run_command(*args):
"""
Example from:
http://asyncio.readthedocs.io/en/latest/subprocess.html
"""
# Create
a NotImplementedError
oh, gross that
apparently its a bug that needs to be fixed in the next version of asyncio
so i wasted 2 days trying database stuff when the lib was broken :P
not yet
i just gave up
i was like not worth it
might was well do it in a json file
its easier
is there a way to append to an existing json folder?
"Expense": {
"Name": "OneTel Mobile Bill",
"Amount": "39.90",
"Due": "28/12/2011",
"Recurrence": "1 Months",
"Paid": "0",
"LastPaid": "01/01/2002"
}
}```
^ init
"Expense": {
"Name": "OneTel Mobile Bill",
"Amount": "39.90",
"Due": "28/12/2011",
"Recurrence": "1 Months",
"Paid": "0",
"LastPaid": "01/01/2002"
},
"Expense": {
"Name": "Loan Repayment",
"Amount": "50.00",
"Due": "08/03/2012",
"Recurrence": "3 Months",
"Paid": "0",
"LastPaid": "08/12/2011"
}
}```
^^ end result
this is just an example
please @ me if you have a solution
It looks like Java (or at least not like python) - so probably not in here, no
It's related to SQL but I don't understand it
database
I don't understand what it means, but I'm really interested to know what it's talking about
like the general idea.
Hi, I need to setup aiosqlite for my discord bot.
I've done the pip install command and yeah. But I know nothing about except that it's supposed to be good for bots. (Been told in #discord-bots).
Anywho, is there anyone in here that can help me setup so I can log everytime somebody get's banned? I already have a ban command. I don't have any line of code about it in my script yet, that is why I am here.
Let me know if you can help me, thanks alot.
Have you looked at their documentation?
aiosqlite is just a async version of sqlite, which is basically a .txt file on steroids
Should be fairly similar to using sqlite, but with a bit more contextmanagers
I'm not very good at sqlite either.
Kinda new to databases, and python overall ngl
I can see the examples in the docs
async with aiosqlite.connect(...) as db:
await db.execute("INSERT INTO some_table ...")
await db.commit()
async with db.execute("SELECT * FROM some_table") as cursor:
async for row in cursor:
...``` This is probably the 2 easiest usecases
Where do I put it? That is what I can't figure out.
first being a normal insert, 2nd part being a select
Whereever you're doing the sql operation
So whenever I am logging it?
@bot.command()
async def ban(ctx):
embed=discord.Embed(
title="User Banned!",
color=0xff9100,
description=f"**User:** {member.mention}\n**Reason:** {reason}\n**Bot's Note:** {member} has been banned from {ctx.guild}!"
)
embed.set_footer(text=f"Banned by {ctx.message.author}")
await ctx.send(embed=embed)
async with aiosqlite.connect(...) as db: <--------
await db.execute("INSERT INTO some_table ...")
await db.commit() <-------
await member.ban(reason=reason)
``` Like that?
async def somecommand(ctx, store_this):
async with aiosqlite.connect(...) as db:
await db.execute("INSERT INTO memos", (store_this, ctx.author.id))
await db.commit()``` etc
given memos is a table with str | author
You need to make sure the execute and commit is inside the db context
preferably
and why wouldn't you have quotes around a string?
uh
Why would you keep those?
Bro
You still need to name it something
have you defined bans?
Nope.
Then no
How do I define it?
well, it's the name of the file you want to be your database
Yeah.
so you define it as a string
That was what I asked before
Oh, right.
async with aiosqlite.connect("bans") as db:?
sure
Sweet.
I'd still call it bans.db though
Will do.
so you know what it is
Now don't forget to create the table before inserting.
Something like that
You'll have to dig around if the syntax is correct for sqlite
I don't remember fully
Not every db supports IF NOT EXISTS
Lemme google real quick
Brb
Let's just do it without IF NTO EXISTS
I can just remove the code line after I ran it the first time
Oh, alright.
So
How do I create it?
CREATE TABLE ban_logs(user_id, INT)
Like this?
I'm sure you can experiment with that syntax and create what you're after.
Imma get back to work
I use aiosqlite, and I am trying to insert a variable into the database. I get this as an error: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: 4 values for 3 columns. And I understand the error. But is there any way to fix it?
This is my code:
await db.execute("INSERT INTO ban_logs (user_id, guild_id, reason) values (?, ?, ?, ?)",
(id_on_member, staff_who_banned, id_on_guild, reason))
(This is for my discord bot)
Hi, client.
(user_id, guild_id, reason) 3 columns
(?, ?, ?, ?) 4 values
cant insert 4 into 3
OHHHH
I forgot to add it there.
Thanks alot, bro.
check = conn.execute("SELECT userid, guildid FROM users WHERE guildid=$1 AND userid=$2", (ctx.author.id, ctx.guild.id,)).fetchone()
print(check)
if check == None:
print("I got here")
try:
with conn:
conn.execute("INSERT INTO users (guildid, userid) VALUES ($1, $2)", (ctx.guild.id, ctx.author.id,))
conn.commit()
except Exception as error:
print(error)
else:
print("Nope it exists")```
it just returns None even though it exists
I am using SQLite3
How can i fix that ?
as a workaround, you can set guildid and userid as a composite primary key in your table @torn sphinx
then you dont even need to check
you can just try to insert and catch the failure if it fails
or insert or ignore into
--
With aiosqlite, can I add 1 number each time the info is stored?
or
insert or ignore into
@harsh pulsar i get an error when usingignore
@timber jasper the error message is pretty clear on what the problem is...
i did avatar = await self.bot.db.fetchval("SELECT discordicon FROM discordguildssql.intro WHERE discordicon = $1", str(message.author.avatar_url))
So it looks something like this:
| Number | Reason |
-------------------
0 | NSFW |
1 | Test |
2 | Hacking |
?
yeah but if i execute the command again it's works
@torn sphinx you can use an autoincrement column
How?
autoincrement per user is not easy though
but if i delete the row in db and execute again and write that then it doesn't work
you will have to do that in the query, not when you insert @torn sphinx
Kinda new to databases, try to explain it as easy as possible please.
Also, how do I delete a table using DB Browser for SQLite?
Found it.
Do you know how can i fix that ? @harsh pulsar
@timber jasper look at the error message, do you think you can explain it to me?
it's only say that the url not formed...
@torn sphinx your table is like this, right?
create table ban_log (
user_id integer,
guild_id integer,
reason text,
)
so when you query, you can do this
select
user_id,
guild_id,
reason,
row_number over (user_id, guild_id) AS ban_number
from ban_log
Wait
Query is like get it?
Or what does query mean?
@harsh pulsar 
What I am doing now is for join logs, not ban logs.
@bot.event
async def on_guild_join(guild):
id_on_guild = guild.id
async with aiosqlite.connect("C:/Yoha/db/info_logs.db") as db:
await db.execute("CREATE TABLE join_logs (number int, guild_id int)")
await db.execute("INSERT INTO join_logs (number, guild_id) values (?, ?)",
(number, id_on_guild))
await db.commit()
This is was I have rn
https://www.db-fiddle.com/f/jPwcKcU2eHAEnj9bd8T1xw/0 @torn sphinx
An online SQL database playground for testing, debugging and sharing SQL snippets.
What is all this code? 😳
the left side is creating the example database
the right side is the query to get the data
dont panic
read each line
you know all of this syntax, you have seen it before
And this?
you have seen 'insert' before, yes?
it is example data
press "Run" at the top
to see the output from the query on the right side
Oh
I mean
This is what I want I guess
It's just that
For the join logs, I want it to count every server it joins kinda.
@timber jasper well i don't know the library you are using. but it is clearly expecting a url, but you passed a filename
discordpy and for database asyncpg (Postgresql)
So it'll put a column to the left, the number. And one to the right, the guild id.
And the number one
Will just do +1 everytime it joins a new server
@timber jasper are you just trying to embed from a filename? you might want to ask about that in #discord-bots
and i did: str(message.author.avatar_icon)
| Number | Guild_ID |
-------------------
0 | 1234 |
1 | 18445 |
2 | 123871 |
Like that
ok let me show you how
Thank you.
the problem with that
I don't need to be able to print it out
wait
I just wanna store it
hold on
Ait.
you dont even need the number in the table
?
there are problems with trying to track the number in the database
You are right
what happens if you leave a guild?
do you then update every number that's farther down in the table?
this is best not stored in the database
No.
It's not like that.
I just want to store as many servers as possible
Lol
It shouldn't delete any of it
so the 1st guild you joined will always be 1
and the 13th guild will always be 13
even if you leave the 13th guild later
Yeah.
ok
It will stay in the db
Once the bot joins a server
It's in the db
Forever.
That is what I am thinking
ok
| Number | Guild_ID | ------------------- 0 | 1234 | 1 | 18445 | 2 | 123871 |
@torn sphinx
And this is how the db should look like.
what's your db?
aiosqlite.
making 1000% sure the increment is exactly 1 is actually quite difficult
not sure if sqlite supports unsigned 64bit ints
@harsh pulsar If we can reach 99% that's good for me.
well, it does
@tame ore integer is auto-scaling up to 8 bytes
It's not a super big deal if there is 1 or 2 gaps.
I just don't want there to be gaps everywhere.
https://www.db-fiddle.com/f/dE2GjZkMEp1Wuk9jWLW25N/1 @torn sphinx
An online SQL database playground for testing, debugging and sharing SQL snippets.
this should work, gaps will appear if you try to insert the same guild twice for example
if it's ok to join the same guild twice, you can remove the unique
What's unique?
An online SQL database playground for testing, debugging and sharing SQL snippets.
"unique" means "cannot have duplicates"
oh ok
so if you say guild_id integer unique you can never have 1003 appear twice
see my updated example
@tame ore im not sure either
they just want to have it 🤷♂️

sometimes there's no accounting for taste
and it's more "portable" than relying on rowid which is a very sqlite specific thing
@harsh pulsar So wait. Where did you type unique in this code?
look at the previous version
On Sqlite3 does limiting text length on a column or something similar help reduce size on disk? Or does it not really matter?
If I have a column that defines a type that my application uses, would it be better to just use an integer 0, 1, 2, 3 or have a longer, text column that would have "PERCENTAGE", "FLAT RATE" etc?
Oh there.
So, why can't I just use unique and make it impossible for it to dublicate?
duplicate?*
It shouldn't log it then
if you try to insert and it fails due to uniqueness constraint
you will have a non-sequential jump in the guild number
as per the sqlite3 docs
AKA a gap?
yes
I'll take the gap then.
Because I doubt someone will leave and rejoin the bot 1k times
@craggy holly as far as i know in sqlite it doesn't matter. in other databases it might matter. you can use an integer and then use an IntEnum in your python code, or you can just use a string. whichever is more comfortable to you
And it's easier to spot a gap then it is to spot a different guild id
yeah
So I can just delete it manually.
go with the unique constraint then
So I use version 1?
Ait.
Right, Thanks
ah nvm
you can't have autoincrement that isn't primary key
that's a postgres thing
nvm
go with option 1
@craggy holly for ref https://www.sqlite.org/datatype3.html
@torn sphinx and for your ref https://sqlite.org/autoinc.html
@harsh pulsar 1 more thing
@bot.event
async def on_guild_join(guild):
id_on_guild = guild.id
async with aiosqlite.connect("C:/Yoha/db/info_logs.db") as db:
await db.execute("CREATE TABLE join_logs (number integer primary key autoincrement, guild_id integer unique)")
await db.execute("INSERT INTO join_logs (number, guild_id) values (?, ?)", <---
(number, id_on_guild))
await db.commit()
This is my code
What do I do, lemme make a arrow
At that arrow
What do I put at the "number" part?
@torn sphinx what does the number column signify?
It's just
Number of the line
| Number | Guild_ID |
0 | 1234 |
1 | 18445 |
2 | 123871 |
Like that
@torn sphinx 
don't insert the number @torn sphinx
Alright.
don't create the table each time...
you should write a separate script to create the tables for your application
Sounds like alot of work when I can just do a #
But I got an error
@torn sphinx and I dont think you would want to create the table evertyime you ran on_guild_join?
😐
parameters are of unsupported type
your setup script should have this:
import sqlite3
db = sqlite3.connect("C:/Yoha/db/info_logs.db")
with db:
db.execute("CREATE TABLE join_logs (number integer primary key autoincrement, guild_id integer unique)")
and your bot code should have this:
@bot.event
async def on_guild_join(guild):
async with aiosqlite.connect("C:/Yoha/db/info_logs.db") as db:
await db.execute("INSERT INTO join_logs (guild_id) values (?)", (guild.id,))
await db.commit()
or better yet...
your setup script should have this:
import sqlite3
DB_FILE = "C:/Yoha/db/info_logs.db"
db = sqlite3.connect(DB_FILE)
with db:
db.execute("CREATE TABLE join_logs (number integer primary key autoincrement, guild_id integer unique)")
and your bot code should have this:
DB_FILE = "C:/Yoha/db/info_logs.db"
@bot.event
async def on_guild_join(guild):
async with aiosqlite.connect(DB_FILE) as db:
await db.execute("INSERT INTO join_logs (guild_id) values (?)", (guild.id,))
await db.commit()
also could do this CREATE TABLE [IF NOT EXISTS] but useless
That doesn't work for aiosqlite
I've tried.
👍
use a one-time setup script
How?
i just showed you
write a script that creates all your tables
run that once
then just use your bot
Nah
Seems like alot of work when just removing the line after is easier
Also
It works
But I see now how useless the number thing was
It's literally there.
Anywho, it works
Thanks for the help.
You're the man.
Seems like alot of work when just removing the line after is easier
it's not easier if you have a lot of code
you're welcome. just keep my advice in mind when you have 30 queries not 1 🙂
its pretty self explanitory
there is no column called namescam
your use of string formatting doesnt help
@torn sphinx print where? to the console? to discord?
Discord
in general you just query the data
1 sec.
you got the data from your database
now format it however you want
theres no special magic "format my data for me" function
I want it to look like that
But it should say
Like
What the warning is
Like you said, I need to format it.
But how?
@harsh pulsar 
you are just returning the cursor
How do I do it the correct way then?
cursor = conn.execute('select blah blah')
data = cursor.fetchall()
that gives you a list of rows. each row is a tuple
...
?
I don't understand shit here.
what part don't you understand
list of rows, each row is as tuple
cursor = conn.execute('select a, b from mytable')
data = cursor.fetchall()
data will be like
[
('a1', 'b1'),
('a2', 'b2'),
...
]
Uhhhh.
Let me give you my code
@bot.command()
async def warn(ctx, member : discord.Member, *, reason=None):
embed=discord.Embed(
title="User Warned!",
color=0xff9100,
description=f"{member} has been warned!"
)
embed.set_footer(text=f"Warned by {ctx.message.author}")
await ctx.send(embed=embed)
async with aiosqlite.connect("C:/Yoha/db/mod_logs.db") as db:
#await db.execute("CREATE TABLE warn_logs(user_id int, reason str)")
await db.execute("INSERT INTO warn_logs (user_id, reason) values (?, ?)",
(member.id, reason))
await db.commit()
This is the warn command
And there's nothing wrong with it, right?
where is the query
But let's start at the beginning.
This is my warn command
And I want a warnings command
That shows the warnings
ok
@bot.command()
async def warnings(ctx, member: discord.Member):
warning_data = # query for warning data
embed_val = # create embed
# send embed
Also, this is more of a discord.py question. But do you know how I make it server side? So it won't show the warnings from server x in server y.
just use the guild where the warning was issued
or where the command was sent from
use ctx, it should have that info
Do I have to add guild id or not?
in your database, yes
Brb then
but you should just get it from the ctx,the user should not have to specify
you tell me
im not going to spoon feed you answers, you have all the knowledge and tools you need to do tihs
Less take warnings then
So wait
The query thingy
It's uhhhh
await db.execute("SELECT user_id FROM warn_logs")
?
@harsh pulsar Quick thing
I can't understand how I am supposed to specify what guild it is and what user it is.
So it only shows their warnings
And not everyone's.
await db.execute("SELECT user_id FROM warn_logs WHERE guild_id = ?", (guild.id,))
i dont know if aiosqlite uses ? or $1 or %s for placeholders
look it up in their docs
It uses ?
Alright so.
Now I have what guild it is
Now I have to pinpoint the id to a specific user
@harsh pulsar
I got this when I ran the cmd
what do you think is the cause of that
instead of asking me
stop and think about it
what do you think you are seeing here?
Uhhhhh.
No idea fr.
According to the code.
It should print my user id.
But that's not a user id.
So idk, I literally have no idea what that is.
should it?
warning_data = db.execute("SELECT user_id FROM warn_logs WHERE guild_id = ?", (ctx.guild.id,))
I think so
i'm not a hardass like this all the time, but from what i can tell you have more than enough programming skill
now you need to learn a new skill, that is reading docs and problem solving
so i don't want to just give you the answers
yes. there should be a "homepage" or "documentation" link in there
sometimes the documentation is just bad
if you dont see what you need in the docs, then ask for help
but usually the next step is, if its not in the docs, read the source code
Got it.
Source code?
How did you learn so much? Is it the docs that learns you the most?
Bruh, these docs are one of the bad ones
"API Reference" on the left
Ait.
Roger that.
I'll just close everything
Put on some music
And read
See ya, thanks for all the help. You're the man. 👊
good luck, you can definitely do it
dont be afraid to ask for clarification if something in the docs is truly baffling
like a term that you can't find a definition for
etc.
Having some serious problems importing a module for some reason
I have a django project. Imagine a structure like this
Database
I-models
I---loads.py
I---of.py
|---files.py
I-utils
I---importantFile.py
I---someothershit.py
I am trying to import stuff from models
Current way that it is importing is like this
from Database.models import CanonicalModel, CanonicalDataPoint, Device, \
Device2, Manufacturer, Product, Profile, Unit
This is working for all of my colleagues, but not for me. For some weird reason
Instead, this gives me this error
ModuleNotFoundError: No module named 'omnio_db'
check = conn.execute("SELECT userid, guildid FROM users WHERE EXISTS (SELECT guildid, userid FROM users WHERE guildid=$1 AND userid=$2)", (ctx.author.id, ctx.guild.id,))
res = check.fetchone()
print(res)
if res == None:
print("I got here")
try:
with conn:
conn.execute("INSERT OR IGNORE INTO users (guildid, userid) VALUES ($1, $2)", (ctx.guild.id, ctx.author.id,))
conn.commit()
except Exception as error:
print(error)
else:
print("Nope it exists")```
It returns None even though the record exists. Can someone please help me understand this issue.
I'm not sure why your first query is doubled like that
what do you mean?
Why use EXISTS?
to return a value?
You can just use the (SELECT..) part to do that
SELECT guildid, userid FROM users WHERE guildid=$1 AND userid=$2```so this?
yes
ok
check = conn.execute("SELECT guildid, userid FROM users WHERE guildid=$1 AND userid=$2", (ctx.author.id, ctx.guild.id,)).fetchone()
print(check)
if check:
print("I got here")
try:
with conn:
conn.execute("INSERT OR IGNORE INTO users (guildid, userid) VALUES ($1, $2)", (ctx.guild.id, ctx.author.id,))
conn.commit()
except Exception as error:
print(error)
else:
print("Nope it exists")```
here is the updated version
I cleared all the rows in table users
and it wont create a new one
(I am new to databsases)
Right
you're probably going to want to "if not check"
because right now, it's checking if the rows exists, then trying to insert if it does
rather than what your "nope it exists" message seems to imply
Hm.. have you tried marking userid and guildid as unique?
but when I do that I cant have the userid appear in another record
as well as the guild id
Oh right, sorry. unique together
yeah 😦
Then you shouldn't be able to have dupes
unless it's throwing an error and thats why you say you're getting them?
how do I do that
What database are you using?
unique(column1, column2) in the table definition
EG:
CREATE TABLE testing (
name TEXT,
id1 INTEGER PRIMARY KEY,
id2 INTEGER,
unique(id1, id2)
);
sqlite3 uses ? as placeholders, not $1
im surprised you arent getting syntax errors from sqlite
maybe python 3.8 allows $1 as well?
CREATE TABLE IF NOT EXISTS users (userid INTEGER NOT NULL, team TEXT DEFAULT 'NONE',guildid INTEGER NOT NULL, isteamleader BOOLEAN DEFAULT false) UNIQUE (userid, guildid)```So like this?
dunno
why not make that primary key
CREATE TABLE IF NOT EXISTS users (
userid INTEGER,
guildid INTEGER,
team TEXT DEFAULT 'NONE',
isteamleader BOOLEAN DEFAULT false,
PRIMARY KEY (userid, guildid)
)
like this
same as Unique key
it allows you to have duplicate user id's
just not duplicate userid,guildid pairs
or do you want to allow duplicate pairs too?
in sqlite3 they're "almost" the same yes
ok nvm I need to use PRIMARY KEY haha
so why don't you try it with either PRIMARY KEY (userid, guildid) or UNIQUE (userid, guildid). i prefer PRIMARY KEY because in this case it is semantically the primary key
in which case you can skip the entire if-check-else thing
and your entire code becomes
with conn:
conn.execute("INSERT OR IGNORE INTO users (guildid, userid) VALUES ($1, $2)", (ctx.guild.id, ctx.author.id,))
also if you use with conn: you don't need to also write conn.commit()
up to you.. it's more "wrong" than "unnecessary"
i know
if you use both you are committing twice
Ah drat, that may have been the big issue
maybe sqlite3 is smart enough to optimize that away