Discord Points Bot

paswrd

Administrator
Staff member
Apr 18, 2017
67
2
A Discord bot created in python and built using discord.py to manage user points, display leaderboards, and enable admins to adjust points dynamically via slash commands. I made this to replace all of the outdated / broken points bots scattered from early Discord. This bot is perfect for engaging communities and gamifying participation in your server!

Github - Discord Points Bot - Paswrd

Code Snip:
Code:
@PointsBot.tree.command(name="addpoints", description="Add points to a user.")
async def addpoints(interaction: discord.Interaction, member: discord.Member, points: int):
    if not interaction.user.guild_permissions.administrator:
        await interaction.response.send_message("You do not have permission to use this command.", ephemeral=True)
        return
    add_points(member.id, points)
    await interaction.response.send_message(f"{points} points have been added to {member.mention}.")

@PointsBot.tree.command(name="removepoints", description="Remove points from a user.")
async def removepoints(interaction: discord.Interaction, member: discord.Member, points: int):
    if not interaction.user.guild_permissions.administrator:
        await interaction.response.send_message("You do not have permission to use this command.", ephemeral=True)
        return
    remove_points(member.id, points)
    await interaction.response.send_message(f"{points} points have been removed from {member.mention}.")
 
1749736697928.webp
 
refactored to use aiosqlite, logging, and changed code structure

Github - Discord Points Bot - Paswrd
Code:
    async def update_points(self, user_id, points):

        current_points = await self.get_points(user_id)

        new_points = current_points + points

        async with aiosqlite.connect(self.db_name) as db:

            await db.execute("UPDATE points SET points = ? WHERE user_id = ?", (new_points, user_id))

            await db.commit()

        return new_points


    async def set_points(self, user_id, points):

         async with aiosqlite.connect(self.db_name) as db:

            await self.get_points(user_id)

            await db.execute("UPDATE points SET points = ? WHERE user_id = ?", (points, user_id))

            await db.commit()


    async def get_leaderboard(self, limit=10):

        async with aiosqlite.connect(self.db_name) as db:

            async with db.execute("SELECT user_id, points FROM points ORDER BY points DESC LIMIT ?", (limit,)) as cursor:

                return await cursor.fetchall()