This project has been archived by its maintainers, and is no longer receiving any updates.
Welcome to python-discord-client
Unofficial Python Discord SDK
📍 Note: We have nothing to do with Discord and have not contributed to the Discord documentation!
📍 This project is worked on daily. The releases available on PyPi may differ from those in the Github repository. So please see PyPi for working examples.
Features
- Connect to your Discord account
- Simple handling of authentication
- Access nearly all Discord REST endpoints (synchron and asynchron)
- Websocket Client to receive almost all events
- Create your custom Bots and manage your Guilds
Quick Start
- Register at Discord
- Create a new app or use an existing one at https://discord.com/developers/applications
- Create a bot, set permissions and save your token
python3 -m pip install python-discord-client
Synchron REST Clients
from discoPy.rest.client import Application, User, Guild, Channel, Stage, Webhook
token = 'your-discord-token'
channel = Channel(token=token)
channel.create_message(channel_id='<some-channel-id>', content='Hello World!')
guild = Guild(token=token)
print(guild.get_guild(guild_id='<some-guild-id>'))
stage = Stage(token=token)
print(stage.get_stage_instance(channel_id='<some-channel-id>'))
app = Application(token=token)
print(app.get_application_commands(application_id='<some-app-id>'))
user = User(token=token)
print(user.get_current_user())
# ...
Websockets / WS Client (asynchron)
from discoPy.core.WSClient import WSClient
import asyncio
class CustomClient(WSClient):
async def on_event(self, event) -> None:
print(event) # <- comment this out
if not event or 'op' not in event:
return
if event['op'] == 0: # Dispatch
try:
print(f'Channel: {data["d"]["channel_id"]} | {data["d"]["author"]["username"]}: {data["d"]["content"]}')
# if condition:
# await self.create_message(
# channel_id=channel_id, content='I love it!'
# )
except:
# handle...
pass
elif event['op'] == 3: # Presence Update
print(f'This is OP 3 - {event}')
elif event['op'] == 4: # Voice State Update
print(f'This is OP 4 - {event}')
elif event['op'] == 6: # Resume
print(f'This is OP 6 - {event}')
elif event['op'] == 7: # Reconnect
print(f'This is OP 7 - {event}')
elif event['op'] == 8: # Request Guild Members
print(f'This is OP 8 - {event}')
elif event['op'] == 9: # Invalid Session
print(f'This is OP 9 - Invalid Session! {event}')
elif event['op'] == 10: # Hello
print('Hearbeat interval received!')
elif event['op'] == 11: # Heartbeat ACK
print('Heartbeat Received')
else:
print(f"huh? {event}")
async def main() -> None:
token = '<discord-bot-token>'
#all_intents: list = WSClient.get_intents_list()
ws_client = CustomClient(
token=token,
intents=['DIRECT_MESSAGES', 'GUILDS'],
)
# Almost every endpoint can be accessed via the websocket client.
print(await myclient.get_current_user())
print(await myclient.get_channel('<some-channel-id>'))
# ...
myclient.run() # opens the websocket connection to receive events
while True:
await asyncio.sleep(30)
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main())
Important notes
The implementation of the methods was based on the official documentation of the Discord API. Parameters and endpoints have been adapted to it. On the official page of the Discord API documentation you can see which requirements and parameters are needed for the respective methods.
Note: We have nothing to do with Discord and have not contributed to the Discord documentation!
Methods
All methods below are available via the REST and Websocket Clients.
Application
User
Guild
General
Widgets and Styles
Scheduled Events
| Method | Documentation |
|---|---|
| list_scheduled_events_for_guild | https://discord.com/developers/docs/resources/guild-scheduled-event#list-scheduled-events-for-guild |
| create_guild_scheduled_event | https://discord.com/developers/docs/resources/guild-scheduled-event#create-guild-scheduled-event |
| get_guild_scheduled_event | https://discord.com/developers/docs/resources/guild-scheduled-event#get-guild-scheduled-event |
| modify_guild_scheduled_event | https://discord.com/developers/docs/resources/guild-scheduled-event#modify-guild-scheduled-event |
| delete_guild_scheduled_evend | https://discord.com/developers/docs/resources/guild-scheduled-event#delete-guild-scheduled-event |
| get_guild_scheduled_event_users | https://discord.com/developers/docs/resources/guild-scheduled-event#get-guild-scheduled-event-users |
Guild Templates
| Method | Documentation |
|---|---|
| get_guild_template | https://discord.com/developers/docs/resources/guild-template#get-guild-template |
| create_guild_template | https://discord.com/developers/docs/resources/guild-template#create-guild-from-guild-template |
| get_guild_templates | https://discord.com/developers/docs/resources/guild-template#get-guild-templates |
| create_guild_template | https://discord.com/developers/docs/resources/guild-template#create-guild-template |
| sync_guild_template | https://discord.com/developers/docs/resources/guild-template#sync-guild-template |
| modify_guild_template | https://discord.com/developers/docs/resources/guild-template#modify-guild-template |
| delete_guild_template | https://discord.com/developers/docs/resources/guild-template#delete-guild-template |
Emoji
| Method | Documentation |
|---|---|
| list_guild_emojis | https://discord.com/developers/docs/resources/emoji#list-guild-emojis |
| get_guild_emoji | https://discord.com/developers/docs/resources/emoji#get-guild-emoji |
| create_guild_emoji | https://discord.com/developers/docs/resources/emoji#create-guild-emoji |
| modify_guild_emoji | https://discord.com/developers/docs/resources/emoji#modify-guild-emoji |
| delete_guild_emoji | https://discord.com/developers/docs/resources/emoji#delete-guild-emoji |
Sticker
| Method | Documentation |
|---|---|
| get_sticker | https://discord.com/developers/docs/resources/sticker#get-sticker |
| list_nitro_sticker_packs | https://discord.com/developers/docs/resources/sticker#list-nitro-sticker-packs |
| list_guild_stickers | https://discord.com/developers/docs/resources/sticker#list-guild-stickers |
| get_guild_sticker | https://discord.com/developers/docs/resources/sticker#get-guild-sticker |
| create_guild_sticker | 'https://discord.com/developers/docs/resources/sticker#create-guild-sticker |
| modify_guild_sticker | https://discord.com/developers/docs/resources/sticker#modify-guild-sticker |
| delete_guild_sticker | https://discord.com/developers/docs/resources/sticker#delete-guild-sticker |
Channel
General
Threads
Stage
| Method | Documentation |
|---|---|
| create_stage_instance | https://discord.com/developers/docs/resources/stage-instance#create-stage-instance |
| get_stage_instance | https://discord.com/developers/docs/resources/stage-instance#get-stage-instance |
| modify_stage_instance | https://discord.com/developers/docs/resources/stage-instance#modify-stage-instance |
| delete_stage_instance | https://discord.com/developers/docs/resources/stage-instance#delete-stage-instance |
Webhook
Not implemented:
| Method | Documentation |
|---|---|
| execute_webhook | https://discord.com/developers/docs/resources/webhook#execute-webhook |
| execute_github_compatible_webhook | https://discord.com/developers/docs/resources/webhook#execute-slackcompatible-webhook |
| get_webhook_messages | https://discord.com/developers/docs/resources/webhook#execute-githubcompatible-webhook |
| edit_webhook_messages | https://discord.com/developers/docs/resources/webhook#edit-webhook-message |
| edit_original_interaction_response | https://discord.com/developers/docs/interactions/receiving-and-responding#edit-original-interaction-response |
Todo
- Testing
Release files for python-discord-client 0.7.3.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python-discord-client-0.7.3.8.tar.gz | 37.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_discord_client-0.7.3.8-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 93.5 kB
Release files / python-discord-client-0.7.3.8.tar.gz
| Download URL | python-discord-client-0.7.3.8.tar.gz |
|---|---|
| Size | 37.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c28b3f056b62643133ea1713114b6d25d36011deac0e9eb3346c7b72671a7045
|
|
BLAKE2b-256 checksum How to use checksums |
d7ef227f02f1bda3d6a50cd7a86c256ab276eda862be474502a1bbeae655a625
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
|
Release files / python_discord_client-0.7.3.8-py2.py3-none-any.whl
| Download URL | python_discord_client-0.7.3.8-py2.py3-none-any.whl |
|---|---|
| Size | 56.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
06f743d3beac159f183009c2b607090e4b063222fdee46ddd6f03007bfef8d1a
|
|
BLAKE2b-256 checksum How to use checksums |
2b2d4a075b1ddf2671e509cc5d618d0d213a60f94d9a857be9254d2e591fa54f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
|