From 168aa819a17c3474494e20c3cdc5bb4e16a08cda Mon Sep 17 00:00:00 2001 From: Phxntxm Date: Sat, 9 Jul 2016 10:26:13 -0500 Subject: [PATCH] Added error checking for an already registered nsfw channel --- cogs/mod.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cogs/mod.py b/cogs/mod.py index 3faeaec..ba96705 100644 --- a/cogs/mod.py +++ b/cogs/mod.py @@ -15,9 +15,12 @@ class Mod: """Registers this channel in the database as a 'nsfw' channel''""" cursor = config.connection.cursor() cursor.execute('use {}'.format(config.db_default)) - cursor.execute('insert into nsfw_channels (channel_id) values ("{}")'.format(ctx.message.channel.id)) + try: + cursor.execute('insert into nsfw_channels (channel_id) values ("{}")'.format(ctx.message.channel.id)) + except pymysql.IntegrityError: + await self.bot.say("This channel is already registered as 'nsfw'!") config.connection.commit() - await bot.say("This channel has just been registered as 'nsfw'! Have fun you naughties ;)") + await self.bot.say("This channel has just been registered as 'nsfw'! Have fun you naughties ;)") @commands.command(pass_context=True, no_pm=True) @checks.isAdmin()