Python
A simple Python API wrapper

Notice

This wrapper is intended to function within a discord.py client object and will not function correctly outside of one. More features and functionality will be added going forward

Installation

1
pip install discordspy
Copied!
The project's github can be found here, while it's pypi page can be found here

Features

  • Server count posting
  • Built-in automatic & interval server count posting
  • Built-in voting webhook handler
  • Voting & server posting events

Examples

Auto posting servers

Auto posting posts the server count whenever the bot is added to/removed from a server, while still abiding with our ratelimits. This example also includes an on server post event.
1
from discord.ext import commands
2
import discordspy
3
4
bot = commands.Bot("!")
5
discords = discordspy.Client(bot, DISCORDS_TOKEN, post=discordspy.Post.auto())
6
7
@bot.event
8
async def on_discords_server_post(status):
9
if status == 200:
10
print("Posted the server count:", discords.servers())
11
12
bot.run(TOKEN)
Copied!

Interval posting servers

Interval posting posts the server count at regular specified intervals, by default it is set to 30 minutes. This example also includes an on server post event.
1
from discord.ext import commands
2
import discordspy
3
4
bot = commands.Bot("!")
5
post = discordspy.Post.interval(minutes=30, hours=1)
6
discords = discordspy.Client(bot, DISCORDS_TOKEN, post=post)
7
8
@bot.event
9
async def on_discords_server_post(status):
10
if status == 200:
11
print("Posted the server count:", discords.servers())
12
13
bot.run(TOKEN)
Copied!

Webhook voting event

Setting up webhooks, along with an event to recieve them
IMPORTANT: Your webhook url must end with /discordswebhook if you wish to use a different path, please specify it using the path argument inside the webhook method path="/customwebhook",
IMPORTANT: To recieve webhooks you must have set up port forwarding and specified the port in the webhook section on your bot page, by default the port is 8080
1
from discord.ext import commands
2
import discordspy
3
4
bot = commands.Bot("!")
5
discords = discordspy.Client(bot, DISCORDS_TOKEN)
6
discords.webhook(port=6969, auth="password")
7
8
@bot.event
9
async def on_discords_vote(data):
10
print("Recieved a vote")
11
12
bot.run(TOKEN)
Copied!

Cog example

Using all the features within a cog
1
from discord.ext import commands
2
import discordspy
3
4
class discords_cog(commands.Cog):
5
6
def __init__(self, bot):
7
self.discords = discordspy.Client(bot, DISCORDS_TOKEN)
8
self.discords.webhook(port=6969, auth="password")
9
10
@commands.command()
11
def postservers(self, ctx):
12
self.discords.post_servers()
13
14
@commands.Cog.listener()
15
async def on_discords_server_post(self, status):
16
log_channel = self.bot.get_channel(LOG_CHANNEL_ID)
17
if status == 200:
18
await log_channel.send("Posted the server count")
19
else:
20
await log_channel.send("Failed to post the server count")
21
22
@commands.Cog.listener()
23
async def on_discords_vote(self, data):
24
print("Recieved a vote")
25
26
def setup(bot):
27
bot.add_cog(discords_cog(bot))
Copied!
Last modified 5mo ago