Skip to main content

API wrapper for Discord written in Python

Project description

gp-discord-python

gp-discord-python is an API wrapper for Discord, written in Python.
This library uses Oauth2 for authentication.

Installing

pip install gp-discord-python

Usage

from discord.client import Client
client = Client("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
client.set_bot_token("YOUR_BOT_TOKEN")

To obtain and set an access token, follow this instructions:

  1. Get authorization URL
url = client.authorization_url(redirect_uri="YOUR_REDIRECT_URI")
# This call generates the url necessary to display the pop-up window to perform oauth authentication
# param redirect_uri is required oauth request.
  1. Get access token using code
token = client.exchange_code("YOUR_CODE")
# "code" is the same response code after login with oauth with the above url.
  1. Refresh access token using refresh_token
token = client.refresh_token("YOUR_REFRESH_TOKEN")
# "refresh_token" is the token refresh in response after login with oauth with the above url.

Actions

- Get user info

client.get_user_info()
# Get the info for current user.

- Get by URL

client.get_by_url(url="YOUR_URL")
# Get data for any other URL from Discord API.

- List of channels

client.get_channel_list(guild_id="YOUR_GUILD_ID")
# Get data list for all channels in server account connected
# param guild_id is in the response of access token after exchange code authorization.

- Get messages

client.get_messages(channel_id="YOUR_CHANNEL_ID")
# Get data list for all messages in a channel from server account connected
# param channel_id is in the response of list of channels action's.

- Send message

import json

client.send_messages(
    channel_id="YOUR_CHANNEL_ID", 
    data=json.dumps({"content": "YOUR_MESSAGE_HERE"})
)
# Send message to channel from server account connected
# param channel_id is in the response of list of channels action's.
# param data is the content of message in format json

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gp_discord_python-0.1.0.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

gp_discord_python-0.1.0-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page