A helper module for discord.py
Project description
discord-helpers
A helper module for discord.py
Current Features (v0.1.0)
- Per server custom prefixes using SQLite3 - aiosqlite
- Invite tracker
- Paginator
- Chatbot coroutine to get a reply from an AI (The Random Stuff API)
- A cycling status for your bot
- A function to create a rich embed with every feature in a simple line of code
- A coroutine to find a webhook from a channel and send a message via it
- Coroutines for using the GET and POST methods easily
Installation
Stable Release:
pip install -U discord-helpers
pip install -U discord-helpers[sqlite]
Development:
pip install -U git+https://github.com/Dorukyum/discord-helpers.git
Some Examples
Prefixes
import discord
from discord.ext import commands, helpers
bot = commands.Bot(command_prefix = "!", intents = discord.Intents.all())
@bot.event
async def on_ready():
bot.db = helpers.Database(bot, "data.db") # also used in the examples below
bot.command_prefix = bot.db.custom_prefix("!")
@bot.event
async def on_message(message):
if message.mentions[0] == client.user:
await bot.db.reply_with_prefix(message)
@bot.command()
async def change_prefix(ctx, *, prefix):
await bot.db.change_prefix(ctx.guild.id, prefix)
await ctx.send(f"Successfuly changed the prefix to `{prefix}`.")
Chatbot
@bot.event
async def on_message(message):
if message.channel.id == my_chatbot_channel_id:
response = await helpers.chatbot(message.content, api_key=my_api_key)
await message.reply(response)
Paginator
@bot.command()
async def send_pages(ctx):
paginator = helpers.Paginator(bot, pages=[
discord.Embed(title="Page 1"),
discord.Embed(title="Page 2"),
])
paginator.add_page(discord.Embed(title="Page 3"))
await paginator.start(ctx)
Invite Tracker
tracker = helpers.InviteTracker(bot, "data.db") # with a database
tracker = helpers.InviteTracker(bot) # without a database, cached
@bot.event
async def on_invite_create(inv):
await bot.tracker.add_invite(inv)
# and so on for the guild_join, guild_remove and invite_delete events
@bot.event
async def on_member_join(member):
inviter, invite = await tracker.track(member)
await bot.get_channel(my_channel_id).send(inviter.name)
await tracker.increment_uses(invite, 1)
Webhooks
@bot.command()
async def send_webhook(ctx, *, text):
await helpers.Webhooks.find_and_send(text, channel=ctx.channel, webhook_name="Test")
Status
bot.status = helpers.StatusCycle("status 1", "status 2")
@tasks.loop(minutes=3)
async def change_status():
await bot.change_presence(activity=discord.Game(bot.status.next()))
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
Built Distribution
Close
Hashes for discord-helpers-0.1.0.linux-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 330b7ab8ace65b880815b335c888117bd6a25c5b82af5bc56858d2d56f427326 |
|
MD5 | 0a75ef946871cfc12e49cf4826726c14 |
|
BLAKE2b-256 | 95c680e7f38b2e0082e5681a950805a3826825931148720cb53419fec56307fd |
Close
Hashes for discord_helpers-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffa518cf6f9d70efd8155c69b5a6516ab505d9532678cb172ec6ca22811a90d4 |
|
MD5 | 8c3da7175e34f25a179c0c712a585dac |
|
BLAKE2b-256 | 4bda28c469cfa32a9fa7ba7590b5420a5149236d524ead67ac8832e97ac0bf6a |