A baisc interface for discord bots to handle receiveing commands using the discord.py package.
Project description
MehlBot
MehlBot is a Discord bot that responds to commands by executing (callback) functions.
It's built around the discord.Client
class.
This allows an easy integration to existing bots and creation of new bots.
Documentation: docs
See examples/hellow_bot.py for full source code.
# imports ...
class HelloBot(discord.Client): # discord.Client class
def __init__(self, intents: Intents, **options) -> None:
super().__init__(intents=intents, **options)
async def on_ready(self) -> None: # Gets called when bot is ready/started
print("Bot started.")
async def on_message(self, message: Message):
if message.author == self.user: # skip if message's author is the bot
return
# necessary callback command
# bot_commands are in mehlbot.command
command_found = await command_callback.process_command(self, bot_commands, message)
# prefix with command if message is command
log_msg = "" if not command_found else "command: "
log_msg += f"{message.author.nick} ({message.author.name}): '{message.content}'"
print(log_msg)
def main():
hello_bot = HelloBot(discord.Intents.all()) # discord intents
with Path("token.txt").open() as file: # load token form file (.gitignore) or use env
token = file.read()
hello_bot.run(token)
And this shows how to add commands
from mehlbot.command import add_command
async def _add(message: discord.Message, client: discord.Client, args: List):
url = args[0]
...
async def _export_playlist(message: discord.Message, client: discord.Client, args: List):
playlist = args[0]
...
add_command("add", _add,
allowed_num_args=[["url"]], # requires exactly 1 argument
description="Adds the given YouTube url to the current playlist.")
add_command("export playlist", _export_playlist,
allowed_num_args=[[], ["playlist_name"]], # either 0 or 1 arg
description="Exports urls of current playlist or of given playlist.")
Dev
poetry run task --list
to show all defined tasks to run. (run task with:poetry run task <task>
)- note
make html
-> rst files copy into source folder, otherwise moduels not found
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
mehlbot-1.1.2.tar.gz
(7.9 kB
view details)
Built Distribution
File details
Details for the file mehlbot-1.1.2.tar.gz
.
File metadata
- Download URL: mehlbot-1.1.2.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.11.1 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eae2ffa5e290942944332074b0babd39d9322008ef6ee7b6573c86ba0f6f3ae7 |
|
MD5 | 56dcc1cafd95415161ddd95deaf45034 |
|
BLAKE2b-256 | d0948a18c3dc8944f60ab29367d6a252b3de1aaeec867402d5fedb3cd8218287 |
File details
Details for the file mehlbot-1.1.2-py3-none-any.whl
.
File metadata
- Download URL: mehlbot-1.1.2-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.11.1 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14d4523b1c4e042ea6ba71f32a6cfaecfae5d2d2f3e76070829b3ca733e4cf35 |
|
MD5 | 0a93ffd621071fd432e96df3341b9f2e |
|
BLAKE2b-256 | 217864fa2492c75a8b535cd5873d145099662aed3de34e9fab3444b265b33897 |