Guest User

Untitled

a guest
May 14th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #setup
  2. connection = sqlite3.connect("data/database.db")
  3. cursor = connection.cursor()
  4. cursor.execute("CREATE TABLE IF NOT EXISTS Roles (roleid INTEGER PRIMARY KEY UNIQUE)")
  5. cursor.execute("CREATE TABLE IF NOT EXISTS Users (userid INTEGER PRIMARY KEY UNIQUE, roleids TEXT)")
  6. connection.commit()
  7.  
  8. #verify
  9. @plugin.slash_command(name="verify-data", description="Verifies all data is stored correctly")
  10. async def verify_integ(self, inter:CommandInteraction):
  11.     cursor.execute("SELECT * FROM Roles")
  12.     roles = cursor.fetchall()
  13.    
  14.     cursor.execute("SELECT * FROM Users")
  15.     users = cursor.fetchall()
  16.     await inter.response.send_message(f"ROLES\n{roles}\n\nUSERS\n{users}")
  17.  
  18. #member update
  19. @plugin.listener("on_member_update")
  20. async def member_update(before:Member, after:Member):
  21.     beforef = [role.id for role in before.roles]
  22.     afterf = [role.id for role in after.roles]
  23.     removed_roles = set(beforef) - set(afterf)
  24.     cursor.execute("SELECT * FROM Users WHERE ? IN (roleids)", (str(list(removed_roles)[0]),))
  25.     users = cursor.fetchall()
  26.     print(users)
Advertisement
Add Comment
Please, Sign In to add comment