mehlbot


Namemehlbot JSON
Version 1.1.3 PyPI version JSON
download
home_pagehttps://github.com/cobrapitz/MehlBot
SummaryA basic interface for Discord bots to handle receiving commands using the discord.py package.
upload_time2023-03-17 19:17:25
maintainer
docs_urlNone
authorK Brandl
requires_python>=3.8.1,<4.0.0
licenseMIT
keywords discord discord.py discord-bot discord-command-bot python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <a href="https://raw.github.com/cobrapitz/MehlBot/master/docs/badges/interrogate-badge.svg"><img alt="PyPI" src="https://raw.github.com/cobrapitz/MehlBot/master/docs/badges/interrogate-badge.svg"></a>
<a href="https://github.com/cobrapitz/MehlBot/blob/master/LICENSE"><img alt="PyPI" src="https://img.shields.io/github/license/cobrapitz/mehlbot"></a>
<a href="https://github.com/cobrapitz/MehlBot"><img alt="PyPI" src="https://img.shields.io/badge/mehl-bot-f39f37"></a>
<a href="https://pypi.org/project/mehlbot/"><img alt="PyPI" src="https://img.shields.io/pypi/v/mehlbot"></a>
<a href='https://mehlbot.readthedocs.io/en/latest/?badge=latest'><img src='https://readthedocs.org/projects/mehlbot/badge/?version=latest' alt='Documentation Status' /></a>


[//]: # (<a href="https://github.com/psf/black"><img alt="PyPI" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>)
[//]: # (<a href="https://pypi.org/project/mehlbot/"><img alt="PyPI" src="https://img.shields.io/badge/mehl-bot-f39f37"></a>)
[//]: # (![t]&#40;https://app.codecov.io/gh/cobrapitz/mehlbot&#41;)
[//]: # ([![security: bandit]&#40;https://img.shields.io/badge/security-bandit-yellow.svg&#41;]&#40;https://github.com/PyCQA/bandit&#41;)
[//]: # (![example workflow]&#40;https://github.com/github/docs/actions/workflows/main.yml/badge.svg&#41;)

# 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](https://mehlbot.readthedocs.io/en/latest/)

See [examples/hellow_bot.py](https://github.com/cobrapitz/MehlBot/blob/master/examples/hello_bot.py) for full source code.
```Python
# 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

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

```

- - - 

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cobrapitz/MehlBot",
    "name": "mehlbot",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.1,<4.0.0",
    "maintainer_email": "",
    "keywords": "Discord,discord.py,Discord-Bot,Discord-Command-Bot,Python",
    "author": "K Brandl",
    "author_email": "kbrandla@duck.com",
    "download_url": "https://files.pythonhosted.org/packages/b3/15/c6afb6e6070f468a15d03e290bf6754f87e9b8ad2ca0a58a92f6cdac65a0/mehlbot-1.1.3.tar.gz",
    "platform": null,
    "description": "<a href=\"https://raw.github.com/cobrapitz/MehlBot/master/docs/badges/interrogate-badge.svg\"><img alt=\"PyPI\" src=\"https://raw.github.com/cobrapitz/MehlBot/master/docs/badges/interrogate-badge.svg\"></a>\n<a href=\"https://github.com/cobrapitz/MehlBot/blob/master/LICENSE\"><img alt=\"PyPI\" src=\"https://img.shields.io/github/license/cobrapitz/mehlbot\"></a>\n<a href=\"https://github.com/cobrapitz/MehlBot\"><img alt=\"PyPI\" src=\"https://img.shields.io/badge/mehl-bot-f39f37\"></a>\n<a href=\"https://pypi.org/project/mehlbot/\"><img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/mehlbot\"></a>\n<a href='https://mehlbot.readthedocs.io/en/latest/?badge=latest'><img src='https://readthedocs.org/projects/mehlbot/badge/?version=latest' alt='Documentation Status' /></a>\n\n\n[//]: # (<a href=\"https://github.com/psf/black\"><img alt=\"PyPI\" src=\"https://img.shields.io/badge/code%20style-black-000000.svg\"></a>)\n[//]: # (<a href=\"https://pypi.org/project/mehlbot/\"><img alt=\"PyPI\" src=\"https://img.shields.io/badge/mehl-bot-f39f37\"></a>)\n[//]: # (![t]&#40;https://app.codecov.io/gh/cobrapitz/mehlbot&#41;)\n[//]: # ([![security: bandit]&#40;https://img.shields.io/badge/security-bandit-yellow.svg&#41;]&#40;https://github.com/PyCQA/bandit&#41;)\n[//]: # (![example workflow]&#40;https://github.com/github/docs/actions/workflows/main.yml/badge.svg&#41;)\n\n# MehlBot\n\nMehlBot is a Discord bot that responds to commands by executing (callback) functions.\n\nIt's built around the `discord.Client` class.\nThis allows an easy integration to existing bots and creation of new bots. \n\nDocumentation: [docs](https://mehlbot.readthedocs.io/en/latest/)\n\nSee [examples/hellow_bot.py](https://github.com/cobrapitz/MehlBot/blob/master/examples/hello_bot.py) for full source code.\n```Python\n# imports ... \n\nclass HelloBot(discord.Client):  # discord.Client class\n\n    def __init__(self, intents: Intents, **options) -> None:\n        super().__init__(intents=intents, **options)\n\n    async def on_ready(self) -> None:  # Gets called when bot is ready/started\n        print(\"Bot started.\")\n\n    async def on_message(self, message: Message):\n        if message.author == self.user:  # skip if message's author is the bot\n            return\n\n        # necessary callback command\n        # bot_commands are in mehlbot.command\n        command_found = await command_callback.process_command(self, bot_commands, message)\n\n        # prefix with command if message is command\n        log_msg = \"\" if not command_found else \"command: \"\n        log_msg += f\"{message.author.nick} ({message.author.name}): '{message.content}'\"\n        print(log_msg)\n\n\ndef main():\n    hello_bot = HelloBot(discord.Intents.all())  # discord intents\n    with Path(\"token.txt\").open() as file:  # load token form file (.gitignore) or use env\n        token = file.read()\n    hello_bot.run(token)\n```\n\nAnd this shows how to add commands\n\n```Python\nfrom mehlbot.command import add_command\n\nasync def _add(message: discord.Message, client: discord.Client, args: List):\n    url = args[0]\n    ...\n\nasync def _export_playlist(message: discord.Message, client: discord.Client, args: List):\n    playlist = args[0]\n    ...\n    \nadd_command(\"add\", _add,\n            allowed_num_args=[[\"url\"]], # requires exactly 1 argument\n            description=\"Adds the given YouTube url to the current playlist.\")\n\nadd_command(\"export playlist\", _export_playlist,\n            allowed_num_args=[[], [\"playlist_name\"]], # either 0 or 1 arg\n            description=\"Exports urls of current playlist or of given playlist.\")\n\n```\n\n- - - \n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A basic interface for Discord bots to handle receiving commands using the discord.py package.",
    "version": "1.1.3",
    "split_keywords": [
        "discord",
        "discord.py",
        "discord-bot",
        "discord-command-bot",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "13a5ce2a25f976662d11d69445cf1cf9bfc39706c529d3d505aa4ad84f3754c6",
                "md5": "de292e11b275bf824c5b2a6585e6b0cd",
                "sha256": "4a6181f2d1d1e8b3940951e0c94f39cf24c8b1e1f55b5632305d380e43f9f206"
            },
            "downloads": -1,
            "filename": "mehlbot-1.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "de292e11b275bf824c5b2a6585e6b0cd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.1,<4.0.0",
            "size": 7141,
            "upload_time": "2023-03-17T19:17:23",
            "upload_time_iso_8601": "2023-03-17T19:17:23.473711Z",
            "url": "https://files.pythonhosted.org/packages/13/a5/ce2a25f976662d11d69445cf1cf9bfc39706c529d3d505aa4ad84f3754c6/mehlbot-1.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b315c6afb6e6070f468a15d03e290bf6754f87e9b8ad2ca0a58a92f6cdac65a0",
                "md5": "dcec83684abf14be1b4a868a98455e8b",
                "sha256": "51cc489eb77c4f2282667299e9d9d317693a5b56a440d4632108560a777b41f8"
            },
            "downloads": -1,
            "filename": "mehlbot-1.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "dcec83684abf14be1b4a868a98455e8b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.1,<4.0.0",
            "size": 7756,
            "upload_time": "2023-03-17T19:17:25",
            "upload_time_iso_8601": "2023-03-17T19:17:25.199272Z",
            "url": "https://files.pythonhosted.org/packages/b3/15/c6afb6e6070f468a15d03e290bf6754f87e9b8ad2ca0a58a92f6cdac65a0/mehlbot-1.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-17 19:17:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "cobrapitz",
    "github_project": "MehlBot",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "tox": true,
    "lcname": "mehlbot"
}
        
Elapsed time: 0.09848s