A Python wrapper for the Diffcord API written in Python.
Project description
Diffcord Python SDK
A Python wrapper for the Diffcord API written in Python.
Installation
pip install diffcord
Pycord Example
from diffcord import Client, VoteWebhookListener, UserBotVote, UserVoteInformation
import discord
intents = discord.Intents.default()
bot = discord.Bot(intents=intents)
async def send_stats_success():
""" Handle stats successfully sent to Diffcord
"""
print("Stats sent successfully!")
async def send_stats_failure(e: Exception) -> None:
""" Handle stats failed to send to Diffcord error
"""
print("Stats failed to send:", e)
async def on_vote(vote: UserBotVote) -> None:
""" Handle the vote.
"""
# LOGIC HERE... (give rewards, etc.)
# example: send a DM to the user who voted
user = await bot.fetch_user(vote.user_id) # Get the discord user object from the user id
await user.send("Thanks for voting!") # Send a DM to the user who voted
# create Diffcord client & webhook listener
# "port" represents the port to listen on for incoming vote webhooks from Diffcord, choose any port you would like which is not in use
diff_webhook_listener = VoteWebhookListener(port=8080, handle_vote=on_vote, verify_code="WEBHOOK_AUTH_CODE_HERE")
diff_client = Client(bot, "YOUR_DIFFCORD_API_TOKEN", diff_webhook_listener,
send_stats_success=send_stats_success, send_stats_failure=send_stats_failure)
# on startup event
@bot.event
async def on_ready():
# start the webhook listener & start send stats
await diff_client.start() # required
@bot.slash_command(name="example")
async def example_command(ctx):
# get user vote info
user_vote_info: UserVoteInformation = await diff_client.get_user_vote_info(ctx.author.id)
# get amount of bot votes this month
bot_votes_this_month: int = await diff_client.bot_votes_this_month()
# respond
message = f"You have voted {user_vote_info.monthly_votes} times this month! This bot has {bot_votes_this_month} votes this month!"
await ctx.respond(message)
bot.run("YOUR_BOT_TOKEN")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
diffcord-0.0.7.tar.gz
(7.7 kB
view details)
Built Distribution
File details
Details for the file diffcord-0.0.7.tar.gz
.
File metadata
- Download URL: diffcord-0.0.7.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f459a4a944196ce1de369c595c0ccae3792d0cd7cfdf6c315bea621183fbe378 |
|
MD5 | 5cb03a43ceebe857b1b79690308b664a |
|
BLAKE2b-256 | 00b1994ab17e9e8476a170e19ab08fd440b667e8da6aea186cbcc46b3727db3c |
File details
Details for the file diffcord-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: diffcord-0.0.7-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77976e8065b8101c5f2ee475dc0035ae8cbfffc2be847732790ad48c0641ab50 |
|
MD5 | 2b9ef65e5a49b41d4c25bfcabf37332a |
|
BLAKE2b-256 | 7375429e1c010668620d8b0498874fff42f2bbccc797d77022f0b01e72a412d6 |