Skip to main content

PyPI PyPI PyPI PyPI Documentation Status

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.")

Release files for mehlbot 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mehlbot 1.1.3
File Size Uploaded
mehlbot-1.1.3.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mehlbot 1.1.3
File Interpreter ABI Platform
mehlbot-1.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / mehlbot-1.1.3.tar.gz

Download URL mehlbot-1.1.3.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
51cc489eb77c4f2282667299e9d9d317693a5b56a440d4632108560a777b41f8
BLAKE2b-256 checksum
How to use checksums
b315c6afb6e6070f468a15d03e290bf6754f87e9b8ad2ca0a58a92f6cdac65a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.0 CPython/3.11.1 Windows/10

Release files / mehlbot-1.1.3-py3-none-any.whl

Download URL mehlbot-1.1.3-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a6181f2d1d1e8b3940951e0c94f39cf24c8b1e1f55b5632305d380e43f9f206
BLAKE2b-256 checksum
How to use checksums
13a5ce2a25f976662d11d69445cf1cf9bfc39706c529d3d505aa4ad84f3754c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.0 CPython/3.11.1 Windows/10

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page