discordgpt


Namediscordgpt JSON
Version 0.1.1 PyPI version JSON
download
home_page
SummaryA package for making a Discord ChatGPT bot
upload_time2023-05-10 16:49:55
maintainer
docs_urlNone
authorAljo
requires_python
licenseMIT License Copyright (c) [year] [fullname] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords chatgpt discord bot openai
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # DiscordGPT
This is a package to use ChatGPT in Discord.

## Installation
You can download the source here, or use `pip` to install the package: 
```
pip install discordgpt
```

## Usage, examples
You can use the `DiscordGPT` class to make a ChatGPT bot:
```py
from discordgpt import DiscordGPT

DiscordGPT(token="your bot token", api_key="your openai api key", channel_id="a channel id for the chat")
```
This creates a ChatGPT bot that responds when someone sends a message in the specified channel id.

You can customize it further by creating a class with DiscordGPT as its superclass:
```py
from discordgpt import DiscordGPT

class MyDiscordGPT(DiscordGPT):
      def __init__(self): super().__init__(token="bot token", api_key="openai api key", channel_id="a channel id", <more options if you need>)
      async def new_question(self, message):
        # you can really do anything here, a bad word checker is just an example
        if "a bad word" in message.content: return await message.channel.send("Don't say bad words to ChatGPT!")
        await super().new_question(message)

MyDiscordGPT()
```
This will create a bad word blocker for DiscordGPT.
If you want to customize it _even further_, you can overwrite the whole process:
```py
from discordgpt import DiscordGPT
import discord
class MyDiscordGPT(DiscordGPT):
      def __init__(self): super().__init__(token="bot token", api_key="openai api key", channel_id="a channel id", <more options if you need>)
      async def new_question(self, message):
        response = super().get_response(message) # gets ChatGPT's response
        await message.channel.send(embed=discord.Embed(title="ChatGPT said:", description=response))

MyDiscordGPT()
```
That makes an embed get sent. But keep in mind, this does not do things like log the new messages or send a typing indicator. You can do that yourself, docs are [here](https://discordpy.readthedocs.io).

## Documentation

### `discordgpt.DiscordGPT(token: str, api_key: str, channel_id: Union[int, str], channel_name: str, model: str, prompt: str, message_to_send: str, logger: bool)`

This makes a new Discord ChatGPT bot.

### Parameters
- `token` - Your Discord bot token.
- `api_key` - Your OpenAI API key.
- `channel_id` - The channel id for the bot to check for messages. Can be empty if `channel_name` is passed. Default is `None`.
- `channel_name` - The channel name for the bot to check for messages. Can be empty if `channel_id` is passed. Default is `None`.
- `model` - The model to use. Default is `text-davinci-003` which is also the best model for completions, but you can specify yours (fine-tunes also work)
- `prompt` - The prompt to give ChatGPT. Default is `"User: {message}\n\nAssistant:\n\n"`. If you give it a custom prompt, put `{message}` where you want the message content to be.
- `message_to_send` - The message to be sent in the channel. Default is `"{response}"`. If you give it a custom message, put `{response}` where you want ChatGPT's response to be.
- `logger` - Whether DiscordGPT should log events like when the bot goes up, when a new message is sent and the response. Default is `True`, can be turned off (by `False`).

### Raises
- `GPTError`, which is just a class for various exceptions, such as `{message}` or `{response}` missing, or `channel_id` and `channel_name` missing.

### Methods
- `new_question` - runs when a message is sent in the right channel. Accepts `message` (which is a `discord.Message` instance) from which it gets the content and author.
- `get_response` - runs when the code needs ChatGPT's response to the message. It also accepts `message` as an argument, it's also a `discord.Message` instance, and it uses it for the content.

All of those are customizable. There's also `_log` which takes a colorama's Style attribute and the text to log, in case you ever need it.

## That should be it!
If you don't know how to get an API key, get it [here](https://platform.openai.com/account/api-keys).

If you don't know how to make a bot and get its token, you can do that [here](https://discord.com/developers). There's a lot of tutorials online, if anything's not clear.

Keep in mind that OpenAI is not free forever and even if ChatGPT is free on https://chat.openai.com, it's not free forever in the API. You get $5 for free when registering, and you should be good for quite a while. The pricing list is [here](https://openai.com/pricing) (we don't use gpt-4 or gpt-3.5 turbo btw, we use davinci which is the best single reply gpt-3 model). If you don't know what a token is, you can check and test it [here](https://platform.openai.com/tokenizer).

# Happy GPTing!

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "discordgpt",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "ChatGPT,Discord,bot,openai",
    "author": "Aljo",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/83/77/306cda7a94d20a84080ba294bcf0005a3af2880bee1973cc9eb7ae350629/discordgpt-0.1.1.tar.gz",
    "platform": null,
    "description": "# DiscordGPT\r\nThis is a package to use ChatGPT in Discord.\r\n\r\n## Installation\r\nYou can download the source here, or use `pip` to install the package: \r\n```\r\npip install discordgpt\r\n```\r\n\r\n## Usage, examples\r\nYou can use the `DiscordGPT` class to make a ChatGPT bot:\r\n```py\r\nfrom discordgpt import DiscordGPT\r\n\r\nDiscordGPT(token=\"your bot token\", api_key=\"your openai api key\", channel_id=\"a channel id for the chat\")\r\n```\r\nThis creates a ChatGPT bot that responds when someone sends a message in the specified channel id.\r\n\r\nYou can customize it further by creating a class with DiscordGPT as its superclass:\r\n```py\r\nfrom discordgpt import DiscordGPT\r\n\r\nclass MyDiscordGPT(DiscordGPT):\r\n      def __init__(self): super().__init__(token=\"bot token\", api_key=\"openai api key\", channel_id=\"a channel id\", <more options if you need>)\r\n      async def new_question(self, message):\r\n        # you can really do anything here, a bad word checker is just an example\r\n        if \"a bad word\" in message.content: return await message.channel.send(\"Don't say bad words to ChatGPT!\")\r\n        await super().new_question(message)\r\n\r\nMyDiscordGPT()\r\n```\r\nThis will create a bad word blocker for DiscordGPT.\r\nIf you want to customize it _even further_, you can overwrite the whole process:\r\n```py\r\nfrom discordgpt import DiscordGPT\r\nimport discord\r\nclass MyDiscordGPT(DiscordGPT):\r\n      def __init__(self): super().__init__(token=\"bot token\", api_key=\"openai api key\", channel_id=\"a channel id\", <more options if you need>)\r\n      async def new_question(self, message):\r\n        response = super().get_response(message) # gets ChatGPT's response\r\n        await message.channel.send(embed=discord.Embed(title=\"ChatGPT said:\", description=response))\r\n\r\nMyDiscordGPT()\r\n```\r\nThat makes an embed get sent. But keep in mind, this does not do things like log the new messages or send a typing indicator. You can do that yourself, docs are [here](https://discordpy.readthedocs.io).\r\n\r\n## Documentation\r\n\r\n### `discordgpt.DiscordGPT(token: str, api_key: str, channel_id: Union[int, str], channel_name: str, model: str, prompt: str, message_to_send: str, logger: bool)`\r\n\r\nThis makes a new Discord ChatGPT bot.\r\n\r\n### Parameters\r\n- `token` - Your Discord bot token.\r\n- `api_key` - Your OpenAI API key.\r\n- `channel_id` - The channel id for the bot to check for messages. Can be empty if `channel_name` is passed. Default is `None`.\r\n- `channel_name` - The channel name for the bot to check for messages. Can be empty if `channel_id` is passed. Default is `None`.\r\n- `model` - The model to use. Default is `text-davinci-003` which is also the best model for completions, but you can specify yours (fine-tunes also work)\r\n- `prompt` - The prompt to give ChatGPT. Default is `\"User: {message}\\n\\nAssistant:\\n\\n\"`. If you give it a custom prompt, put `{message}` where you want the message content to be.\r\n- `message_to_send` - The message to be sent in the channel. Default is `\"{response}\"`. If you give it a custom message, put `{response}` where you want ChatGPT's response to be.\r\n- `logger` - Whether DiscordGPT should log events like when the bot goes up, when a new message is sent and the response. Default is `True`, can be turned off (by `False`).\r\n\r\n### Raises\r\n- `GPTError`, which is just a class for various exceptions, such as `{message}` or `{response}` missing, or `channel_id` and `channel_name` missing.\r\n\r\n### Methods\r\n- `new_question` - runs when a message is sent in the right channel. Accepts `message` (which is a `discord.Message` instance) from which it gets the content and author.\r\n- `get_response` - runs when the code needs ChatGPT's response to the message. It also accepts `message` as an argument, it's also a `discord.Message` instance, and it uses it for the content.\r\n\r\nAll of those are customizable. There's also `_log` which takes a colorama's Style attribute and the text to log, in case you ever need it.\r\n\r\n## That should be it!\r\nIf you don't know how to get an API key, get it [here](https://platform.openai.com/account/api-keys).\r\n\r\nIf you don't know how to make a bot and get its token, you can do that [here](https://discord.com/developers). There's a lot of tutorials online, if anything's not clear.\r\n\r\nKeep in mind that OpenAI is not free forever and even if ChatGPT is free on https://chat.openai.com, it's not free forever in the API. You get $5 for free when registering, and you should be good for quite a while. The pricing list is [here](https://openai.com/pricing) (we don't use gpt-4 or gpt-3.5 turbo btw, we use davinci which is the best single reply gpt-3 model). If you don't know what a token is, you can check and test it [here](https://platform.openai.com/tokenizer).\r\n\r\n# Happy GPTing!\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) [year] [fullname]  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A package for making a Discord ChatGPT bot",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/Aljoberg/DiscordGPT",
        "Repository": "https://github.com/Aljoberg/DiscordGPT"
    },
    "split_keywords": [
        "chatgpt",
        "discord",
        "bot",
        "openai"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "524efd04e83475da7f842a844d1702760a9a49306692cb4f7d8ea76d5482d300",
                "md5": "9c4436f154e36757915c307324ae1020",
                "sha256": "f4e9068e375abadae017f4ec4e8d96983808d95c103b38e718c28bad88548e72"
            },
            "downloads": -1,
            "filename": "discordgpt-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9c4436f154e36757915c307324ae1020",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6394,
            "upload_time": "2023-05-10T16:49:51",
            "upload_time_iso_8601": "2023-05-10T16:49:51.571459Z",
            "url": "https://files.pythonhosted.org/packages/52/4e/fd04e83475da7f842a844d1702760a9a49306692cb4f7d8ea76d5482d300/discordgpt-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8377306cda7a94d20a84080ba294bcf0005a3af2880bee1973cc9eb7ae350629",
                "md5": "50cf4d20ebb45c4d446ac4f6328afc4d",
                "sha256": "5e3ff9a9a76f8ac1c4130aecf7f042a77754751e9d6e63d71132a76d73b7fb03"
            },
            "downloads": -1,
            "filename": "discordgpt-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "50cf4d20ebb45c4d446ac4f6328afc4d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5249,
            "upload_time": "2023-05-10T16:49:55",
            "upload_time_iso_8601": "2023-05-10T16:49:55.580909Z",
            "url": "https://files.pythonhosted.org/packages/83/77/306cda7a94d20a84080ba294bcf0005a3af2880bee1973cc9eb7ae350629/discordgpt-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-10 16:49:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Aljoberg",
    "github_project": "DiscordGPT",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "discordgpt"
}
        
Elapsed time: 0.06761s