Skip to main content

A leveling cog for discord bots

Project description

Dislevel

Making leveling easier for small as well as big bot

Installation

pip install dislevel

Usage

Making a simple bot with a db connection. First of all we need a database connection. Dislevel supports 2 type of database connection,

  • asyncpg (Pool)
  • databases (Database)

If your bot already have a connection you can use that, Or you can create a new one for leveling. In this example I will create a new connection using databases[sqlite]

from databases import Database
from discord import Intents
from discord.ext import commands

from dislevel import init_dislevel
from dislevel.utils import update_xp

intents = Intents.default()
# Nextcord current version uses discord Api v9 where message content intent is not enforced. 
# If you ware are using discord.py when you will need to enable message_content intent manually as shown below
intents.message_content = True

bot = commands.Bot(command_prefix="?", intents=intents)


@bot.event
async def on_ready():
    # Using databases to create a sqlite db
    db = Database("sqlite:///leveling.db")
    await db.connect()

    # Pass instance of bot, the database connection and specify which driver to use. In this case we are using databases so we passed that
    await init_dislevel(bot, db, "databases") 

    # Load the cog. It has two cogs. `dislevel.nextcord`, `dislevel.dpy`
    bot.load_extension("dislevel.dpy")

    print("Ready! Let's go...")


@bot.event
async def on_message(message):
    if message.author.bot:
        return
    
    # You can use this method anywhere to update xp of a member
    # First pass the bot instance, member_id, guild_id and how much xp to be added.
    await update_xp(bot, message.author.id, message.guild.id, amount=10)

    await bot.process_commands(message)

TOKEN: str = "Your bot token here"
bot.run(TOKEN)

Events

# If you want to do something when a user level's up!
@bot.event
async def on_dislevel_levelup(guild_id, member_id, level):
    print(f"Member level up! ID: {member_id}")

Commands

rank [member] - See your/member's rank
leaderboard, lb - See leaderboard
setbg <url> - Set your bg url
resetbg - Reset your bg url to default \

Join Discord For any kind of help

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dislevel-2.0.0a1.tar.gz (138.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dislevel-2.0.0a1-py3-none-any.whl (138.8 kB view details)

Uploaded Python 3

File details

Details for the file dislevel-2.0.0a1.tar.gz.

File metadata

  • Download URL: dislevel-2.0.0a1.tar.gz
  • Upload date:
  • Size: 138.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for dislevel-2.0.0a1.tar.gz
Algorithm Hash digest
SHA256 59e73fc10c97e5732074efc2f0a0f2df8d50972203c9b584de4401c58f551768
MD5 685845c331a3f17a4ee49f32c0db1471
BLAKE2b-256 6f3406ea359428345969eec946a640a1f8b594e7c231780d9ee57bccd4feea9f

See more details on using hashes here.

File details

Details for the file dislevel-2.0.0a1-py3-none-any.whl.

File metadata

  • Download URL: dislevel-2.0.0a1-py3-none-any.whl
  • Upload date:
  • Size: 138.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for dislevel-2.0.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 e44a41e3885c401ddb01cedeaf6b7846ff5e76cac05ad1d479f8427b76fead68
MD5 39df7a87ab2857dea33c723396ffde59
BLAKE2b-256 19d14523c83c73b2b8b2d10dfcf13ad0c28d8184742cc3fc3d6191f6ede807e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page