不和谐机器人的调平齿轮
项目描述
失衡
使小型和大型机器人的调平更容易
安装
pip install dislevel
在此处检查示例
用法
使用数据库连接制作一个简单的机器人。首先我们需要一个数据库连接。Dislevel 支持 2 种类型的数据库连接。
asyncpg (Pool)databases (Database)
如果您的机器人已经有一个连接,您可以使用它,或者您可以创建一个新的用于调平。在本例中,我将使用数据库 [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 explicitly 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")
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)
# Load the cog. It has 4 cogs. `dislevel.nextcord`, `dislevel.nextcord.slash`, `dislevel.discord`, `dislevel.discord.slash`
# If you want to use nextcord.slash you should load it ouside on_ready. Otherwise you can load it inside on_ready
# You can also load both slash and normal cog.
bot.load_extension("dislevel.nextcord")
TOKEN: str = "Your bot token here"
bot.run(TOKEN)
活动
# If you want to do something when a user level's up!
async def on_dislevel_levelup(guild_id, member_id, level):
pass
齿轮
-
dislevel.discord- 对于 discord.py 2.0 -
dislevel.discord.slash- 对于 discord.py 2.0(斜杠命令) -
dislevel.nextcord- 对于 nextcord 2.0 -
dislevel.nextcord.slash- 对于 nextcord 2.0(斜线命令)
命令
rank [member] -See your/member's rank
排行榜,lb - See leaderboard
setbg <url> - Set your bg url
resetbg -Reset your bg url to default
加入 Discord寻求任何帮助
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
dislevel-2.0.3.tar.gz
(140.1 kB
查看哈希)
内置分布
dislevel-2.0.3-py3-none-any.whl
(140.8 kB
查看哈希)