From 9303645c37d7986d1402bdab97df91ab5a25695d Mon Sep 17 00:00:00 2001 From: NodeStorm <36058792+QLG1@users.noreply.github.com> Date: Mon, 24 Aug 2020 23:46:12 +0300 Subject: [PATCH] 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 --- bot.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/bot.py b/bot.py index 8bf4117..f19767e 100644 --- a/bot.py +++ b/bot.py @@ -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)