gp-discord-python is an API wrapper for Discord, written in Python.
This library uses Oauth2 for authentication.
pip install gp-discord-python
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:
- 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.
- 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.
- 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.
client.get_user_info()
# Get the info for current user.
client.get_by_url(url="YOUR_URL")
# Get data for any other URL from Discord API.
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.
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.
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