I can’t understand why user data isn’t being entered into the database

I’m creating a discord bot that will enter user data from the server into the database, such as id, username, nickname and roles. For this I use discord.py and Supabase. It doesn’t show any errors in the console.

import discord
from discord.ext import commands

from supabase import create_client, Client

url: str = "my_url"
key: str = "my_key"
supabase: Client = create_client(url, key)

bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())

@bot.event
async def on_ready():
    print("Бот запущен!")

    for  guild in bot.guilds:
        for member in guild.members:
            post = {
                "id": member.id,
                "username": member.name,
                "nickname": member.display_name,
                "role": member.roles
            }

            response = supabase.table("usersDiscord").select("*").eq("id", member.id).execute()
            if response == []:
               response = supabase.table("usersDiscord").insert(post).execute()

@bot.event
async def on_member_join(member):
    post = {
        "id": member.id,
        "username": member.name,
        "nickname": member.display_name,
        "role": member.roles
    }

    response = supabase.table("usersDiscord").select("*").eq("id", member.id).execute()
    if response == []:
        response = supabase.table("usersDiscord").insert(post).execute()

bot.run("my_token")

Perhaps the problem occurs in the place where I am trying to check whether there is already a user with a given id in the database. The purpose of this check is that if such a user exists, then he is not added to the database, and if there is no such user, then he needs to be added.

response = supabase.table("usersDiscord").select("*").eq("id", member.id).execute()
    if response == []:
        response = supabase.table("usersDiscord").insert(post).execute()

1

There could be several reasons why this is not working. On first sight it doesn’t look like it’s a code issue.

  • First (and most likely) I would check on the RLS policies (Enable Row Level Security (RLS)) and see if they are correcly setup (you should be able to read/write to the table you want to make operations to)

  • Another reason could be that you are saving on fields that are supposed to be of a format that is not correct (for example ID set to be INT(8) and you are saving a string there)

  • Another reason could be that the fields you are trying to write to are already propagated, or they are part of some other table constrain like a primary key on another table that doesn’t have that entry.

  • Usually if there is an error on the Supabase side they tend to tell you what’s going on with a reply message. Is there something in the logs that you forgot to post?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật