fix to faulty get_prefix method

get_prefix would throw error if a command was used in DMs, not anymore, there's better fixes out there but this one works for now
This commit is contained in:
NodeStorm 2020-08-24 23:46:12 +03:00 committed by GitHub
parent a8765d4c79
commit 9303645c37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 9 deletions

24
bot.py
View File

@ -5,17 +5,23 @@ from discord.ext import commands
import os, sqlite3
def get_prefix(client, message):
conn = sqlite3.connect('db.sqlite3')
curr = conn.cursor()
curr.execute(f'SELECT * FROM guilds WHERE guild_id="{message.guild.id}"')
query = curr.fetchone()
try:
conn = sqlite3.connect('db.sqlite3')
curr = conn.cursor()
curr.execute(f'SELECT * FROM guilds WHERE guild_id="{message.guild.id}"')
query = curr.fetchone()
if query == None:
curr.execute(f"INSERT INTO guilds VALUES ('{message.guild.id}','$')")
conn.commit()
if query == None:
curr.execute(f"INSERT INTO guilds VALUES ('{message.guild.id}','$')")
conn.commit()
prefix = "$"
else:
prefix = query[1]
conn.close()
return prefix
except AttributeError:
conn.close()
return "$"
else:
return query[1]
client = commands.Bot(command_prefix = get_prefix)