A discord bot framework!
Project description
Betterbot
A modern, event-driven bot framework for Python, designed for simplicity and flexibility.
Install
Install via pip:
pip install betterbot
How to Use
Import the Setup module and initialize your bot:
from betterbot import Setup
Example Bot Script
import asyncio
import json
from betterbot import Setup, Events, InteractionTypes
# Load bot token from configuration
with open("config.json") as f:
config = json.load(f)
TOKEN = config["TOKEN"]
class Bot:
def __init__(self):
self.bot = Setup(TOKEN, intents=53608447)
self.bot.debug = True # Enable detailed debug logs
self.rest = self.bot.rest_client
self.bot_username = None
self.event = self.bot.event
async def main(self):
# Register event handlers
await self.event.register(Events.BOT_READY, self.on_ready) # You can register multiple handlers per event.
await self.event.register(Events.MESSAGE_CREATE, self.on_message)
await self.bot.start()
# -----------------------
# Event Handlers
# -----------------------
async def on_ready(self, username, application_id):
self.bot_username = username
print(f"Logged in as {username}")
# Create a guild slash command
await self.rest.create_guild_command(
self.test_command,
application_id=application_id,
guild_id=GUILD_ID,
name="testrest",
description="Test all REST endpoints with defer"
)
async def on_message(self, username, content, channel_id):
if username == self.bot_username:
return
print(f"{username}: {content}")
if content.lower() == "test rest":
await self.test_rest_methods()
# -----------------------
# Slash Command Handler
# -----------------------
async def test_command(self, interaction_id, token):
# Immediately respond to the interaction
await self.rest.send_interaction_callback(
interaction_id,
token,
cmd_type=InteractionTypes.RESPOND_WITH_MESSAGE,
content="Hello, it is starting!"
)
await self.test_rest_methods()
async def test_rest_methods(self):
# -----------------------
# Channel Methods
# -----------------------
await self.rest.send_message(CHANNEL_ID, "Hello from Betterbot REST test!")
messages = await self.rest.get_messages(CHANNEL_ID)
if messages:
msg_id = messages[0]["id"]
await self.rest.typing(CHANNEL_ID)
await self.rest.add_reaction(CHANNEL_ID, msg_id, "👍")
await self.rest.remove_reaction(CHANNEL_ID, msg_id, "👍")
await self.rest.pin_message(CHANNEL_ID, msg_id)
await self.rest.unpin_message(CHANNEL_ID, msg_id)
# -----------------------
# Guild Methods
# -----------------------
guild_info = await self.rest.get_guild_info(GUILD_ID)
members = await self.rest.get_guild_members(GUILD_ID, limit=5)
roles = await self.rest.get_guild_roles(GUILD_ID)
print("REST test complete!")
# -----------------------
# Run Bot
# -----------------------
asyncio.run(Bot().main())
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
betterbot-5.0.0.tar.gz
(36.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
betterbot-5.0.0-py3-none-any.whl
(57.2 kB
view details)
File details
Details for the file betterbot-5.0.0.tar.gz.
File metadata
- Download URL: betterbot-5.0.0.tar.gz
- Upload date:
- Size: 36.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c9ad4c0dd9a51ba43a76bbef072c7cbeba35a7a336392fccf336d4d8a00661a
|
|
| MD5 |
d410d560991487cdebf2dad389b4d96d
|
|
| BLAKE2b-256 |
8599efc5b80303e20bc10ddc688853af326a604dcebb02febf9858f53c0bfeb0
|
File details
Details for the file betterbot-5.0.0-py3-none-any.whl.
File metadata
- Download URL: betterbot-5.0.0-py3-none-any.whl
- Upload date:
- Size: 57.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6691ebee99f5f9dcbea4be78102d8e078bf565fa637c52676865eaf913a112e1
|
|
| MD5 |
2fefd87cdd033a04ef61287b668ea36c
|
|
| BLAKE2b-256 |
42c52743f45fb6ccff2fab73070d283e30d387ebc822fb71dd90aac158b34a0f
|