Cameron222

Untitled

Oct 25th, 2022
1,059
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.55 KB | None | 0 0
  1. db = aiosqlite.connect('report.sqlite')
  2. dbb = aiosqlite.connect('prefix.sqlite')
  3.  
  4. async def check_prefix(client, message):
  5.   cursor = await dbb.cursor()
  6.   await cursor.execute("SELECT prefix FROM prefixes WHERE guild_id=?", (message.guild.id,))
  7.   data = await cursor.fetchone()
  8.   if data:
  9.     return data
  10.   else:
  11.     try:
  12.       await cursor.execute("INSERT INTO prefixes(prefix, guild_id) VALUES(?, ?)", ('??', message.guild.id))
  13.       await dbb.commit()
  14.       await cursor.execute("SELECT prefix FROM prefixes WHERE guild_id=?", (message.guild.id,))
  15.       data = await cursor.fetchone()
  16.       if data:
  17.         await cursor.execute("UPDATE prefixes SET prefix =? WHERE guild_id = ?", ('??', message.guild.id))
  18.         await dbb.commit()
  19.     except Exception as e:
  20.         return '+'
  21.  
  22. class MyClient(commands.AutoShardedBot):
  23.     def __init__(self, *, intents: discord.Intents.default()):
  24.         intents.message_content = True
  25.         super().__init__(intents=intents, command_prefix=commands.when_mentioned_or("+"), help_command=None)
  26.  
  27.  
  28. @client.event
  29. async def on_ready():
  30.     print(discord.__version__)
  31.     print(f'Logged in as {client.user} (ID: {client.user.id})')
  32.     print('------')
  33.     await dbb
  34.     await db
  35.     cursor = await dbb.cursor()
  36.     await cursor.execute("""
  37.  CREATE TABLE IF NOT EXISTS prefixes(
  38.        prefix TEXT,
  39.        guild_id BIGINT
  40.       )""")
  41.     await dbb.commit()
  42.  
  43.  
  44.  
  45. @client.event
  46. async def on_guild_leave(ctx, guild):
  47.   cursor = await dbb.cursor()
  48.   await cursor.execute("SELECT prefix FROM prefixes WHERE guild_id=?", (ctx.guild.id,))
  49.   data = await cursor.fetchone()
  50.   if data:
  51.     await cursor.execute("DELETE FROM prefixes WHERE guild_id=?", (guild.id))
  52.     await dbb.commit()
  53. @client.command()
  54. async def prefix(ctx, prefix: str = None):
  55.   cursor = await dbb.cursor()
  56.   if prefix is None:
  57.     return await ctx.send('put prefix nub')
  58.  
  59.   await cursor.execute("SELECT prefix FROM prefixes WHERE guild_id=?", (ctx.guild.id,))
  60.   data = await cursor.fetchone()
  61.   if data:
  62.     await cursor.execute("UPDATE prefixes SET prefix =? WHERE guild_id = ?", (prefix, ctx.guild.id))
  63.     await dbb.commit()
  64.     return await ctx.send(f'Updated prefix to {prefix}')
  65.  
  66.   await cursor.execute("INSERT INTO prefixes(prefix, guild_id) VALUES(?, ?)", ('??', ctx.guild.id))
  67.   await dbb.commit()
  68.  
  69. @client.event
  70. async def on_guild_join(guild):
  71.   await client.tree.sync(guild=guild)
  72.   cursor = await dbb.cursor()
  73.   await cursor.execute("INSERT INTO prefixes(prefix, guild_id) VALUES(?, ?)", ('??', guild.id))
  74.   await dbb.commit()
  75.  
Advertisement
Add Comment
Please, Sign In to add comment