Unofficial Python Discord SDK
📍 Note: We have nothing to do with Discord and have not contributed to the Discord documentation!
- 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
- 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
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())
# ...
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())
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!
All methods below are available via the REST and Websocket Clients.
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 |
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 |
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 |
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 |
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 |
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 |
- Testing