Skip to content

GearPlug/gp-discord-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages