Skip to main content

Discord API wrapper centered around automation

Project description

Autocord

Autocord is a Python API wrapper for Discord centered around automation. Using Autocord, you can easily send messages, create tasks, and much more. The purpose of Autocord is to provide users with less hassle when using requests.

Installing
Requires python>3.7
pip install autocord

Quick Example

# inialize autocord client
client = autocord.client('TOKEN')

# send the message 'hi'
client.SEND_MESSAGE('Hi', CHANNEL_ID)

# create a task that sends the message 'hi' every 5 seconds
id = client.CREATE_TASK({'Hi', 5}, CHANNEL_ID)
print(client.ongoing_tasks)

# end the task
client.END_TASK(id)

Client

Getting Started
To get started, initialize a client. The client is essentially a request.Session() object with included parameters. Also on initialization, client feches basic metadata to show your id, username, discriminator, and more.

with autocord.client('TOKEN') as client:
    print(client.id)

# or...
    
client = autocord.client('TOKEN')
print(client.id)

Creating Tasks
You can easily create a task using Autocord using the self.CREATE_TASK(messages, channel) function. The messages parameter is a dictionary with message as the key and the interval as the value.

data = {
    # send hi and wait 5 seconds
    'hi': 5,
    # send bye and wait 5 seconds
    'bye': 5
}
client.CREATE_TASK(data, CHANNEL_ID)

Additionally, you can also specify an offset parameter to wait a certain amount of time before starting the thread.

# start thread 10 seconds after being run
client.CREATE_TASK(data, CHANNEL_ID, offset=10)

Ending a task is quite simple. Once a task is created, it is added to self.ongoing_tasks and also returns the task id. You can call the attribute ongoing_tasks or take a value from the CREATE_TASK function to find your task id. To end a task, just call self.ENDTASK(id)

id = client.CREATE_TASK(messages, CHANNEL_ID)
client.END_TASK(id)

# or...

client.CREATE_TASK(messages, CHANNEL_ID)
for task in client.ongoing_tasks:
    client.END_TASK(task)

Creating Groups
You can also create discord groups using self.CREATE_GROUP(users). CREATE_GROUP takes in a list of user id's as a paramter. Creating a group with return a request.response object.

# create a group with user id's 000000 and 111111
client.CREATE_GROUP([000000, 111111])

# getting a response
response = client.CREATE_GROUP([])
print(response.json())

Interacting With Users
You can interact with other users by sending them a friend request, blocking them, and unblocking them.

# all of these methods return request.response objects

# send a friend request to specified user id
client.FRIEND_REQUEST(id)

# block user with specified id
client.BLOCK(id)

# unblock user with specified id
client.UNBLOCK(id)

Utils

You can use autocord.utils to preform miscallaneous tasks. To create a util object, initialize it using:

client = autocord.client('TOKEN')
util = autocord.utils(client)

autocord.util takes in a client object as a parameter.

Fetching Channel History
You can fetch message history from a channel by calling self.FETCH_MESSAGE_HISTORY(CHANNEL_ID). By default, it will fetch 100 messages although you can specify that by changing the limit parameter.

util = autocord.utils(client)

# fetch 100 most recent messages
util.FETCH_MESSAGE_HISTORY(CHANNEL_ID)

# fetch 1000 most recent messages
util.FETCH_MESSAGE_HISTORY(CHANNEL_ID, limit=1000)

By default, FETCH_MESSAGE_HISTORY will wait until it isn't rate limited if discord rate limits you. You can break out of the loop by setting the retry parameter to False.

# try fetching 10,000 messages
# util will wait if it gets rate limited
util.FETCH_MESSAGE_HISTORY(CHANNEL_ID, limit=10000)

# try fetching 10,000 messages
# util will return if it gets rate limited
util.FETCH_MESSAGE_HISTORY(CHANNEL_ID, limit=10000, retry=False)

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

autocord-0.3.2.tar.gz (7.7 kB view hashes)

Uploaded Source

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