# Diffcord Python SDK
A Python wrapper for the Diffcord API written in Python.
## Installation
```
pip install diffcord
```
## Pycord Example
```python
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)
bot.diff_client = diff_client
# 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")
```
Raw data
{
"_id": null,
"home_page": "",
"name": "diffcord",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7.0",
"maintainer_email": "",
"keywords": "diffcord,diffcord-api,diffcord-api-wrapper,diffcord-api-python-wrapper,diffcord-api-python",
"author": "jadelasmar4@gmail.com",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/1e/7c/2708f367e1efd05516f5ac942acb7bdfbc31efe7782ff175deb425521019/diffcord-1.0.2.tar.gz",
"platform": null,
"description": "# Diffcord Python SDK\r\n\r\nA Python wrapper for the Diffcord API written in Python. \r\n\r\n## Installation\r\n```\r\npip install diffcord\r\n```\r\n\r\n\r\n## Pycord Example\r\n\r\n```python\r\nfrom diffcord import Client, VoteWebhookListener, UserBotVote, UserVoteInformation\r\n\r\nimport discord\r\n\r\nintents = discord.Intents.default()\r\n\r\nbot = discord.Bot(intents=intents)\r\n\r\n\r\nasync def send_stats_success():\r\n \"\"\" Handle stats successfully sent to Diffcord\r\n \"\"\"\r\n print(\"Stats sent successfully!\")\r\n\r\n\r\nasync def send_stats_failure(e: Exception) -> None:\r\n \"\"\" Handle stats failed to send to Diffcord error\r\n \"\"\"\r\n print(\"Stats failed to send:\", e)\r\n\r\n\r\nasync def on_vote(vote: UserBotVote) -> None:\r\n \"\"\" Handle the vote.\r\n \"\"\"\r\n # LOGIC HERE... (give rewards, etc.)\r\n\r\n # example: send a DM to the user who voted\r\n user = await bot.fetch_user(vote.user_id) # Get the discord user object from the user id\r\n await user.send(\"Thanks for voting!\") # Send a DM to the user who voted\r\n\r\n\r\n# create Diffcord client & webhook listener\r\n\r\n# \"port\" represents the port to listen on for incoming vote webhooks from Diffcord, choose any port you would like which is not in use\r\ndiff_webhook_listener = VoteWebhookListener(port=8080, handle_vote=on_vote, verify_code=\"WEBHOOK_AUTH_CODE_HERE\")\r\n\r\ndiff_client = Client(bot, \"YOUR_DIFFCORD_API_TOKEN\", diff_webhook_listener,\r\n send_stats_success=send_stats_success, send_stats_failure=send_stats_failure)\r\n\r\nbot.diff_client = diff_client\r\n\r\n# on startup event\r\n@bot.event\r\nasync def on_ready():\r\n # start the webhook listener & start send stats\r\n await diff_client.start() # required\r\n\r\n\r\n@bot.slash_command(name=\"example\")\r\nasync def example_command(ctx):\r\n # get user vote info\r\n user_vote_info: UserVoteInformation = await diff_client.get_user_vote_info(ctx.author.id)\r\n\r\n # get amount of bot votes this month\r\n bot_votes_this_month: int = await diff_client.bot_votes_this_month()\r\n\r\n # respond\r\n message = f\"You have voted {user_vote_info.monthly_votes} times this month! This bot has {bot_votes_this_month} votes this month!\"\r\n await ctx.respond(message)\r\n\r\n\r\nbot.run(\"YOUR_BOT_TOKEN\")\r\n```\r\n",
"bugtrack_url": null,
"license": "",
"summary": "A Python wrapper for the Diffcord API written in Python.",
"version": "1.0.2",
"project_urls": {
"Github": "https://github.com/diff-cord/python-sdk"
},
"split_keywords": [
"diffcord",
"diffcord-api",
"diffcord-api-wrapper",
"diffcord-api-python-wrapper",
"diffcord-api-python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "02e3792036282947791eea001c42c3584abf3d2825e3245d7b33a9fa19049965",
"md5": "c1a66da4a55024ba12577a88362c88da",
"sha256": "fd9c488a3c39446b365d3477cea56e25ea147413957acf5d910dd93b3b3a482f"
},
"downloads": -1,
"filename": "diffcord-1.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c1a66da4a55024ba12577a88362c88da",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7.0",
"size": 7693,
"upload_time": "2023-05-09T20:08:12",
"upload_time_iso_8601": "2023-05-09T20:08:12.379890Z",
"url": "https://files.pythonhosted.org/packages/02/e3/792036282947791eea001c42c3584abf3d2825e3245d7b33a9fa19049965/diffcord-1.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1e7c2708f367e1efd05516f5ac942acb7bdfbc31efe7782ff175deb425521019",
"md5": "c1a9579e473bab0176cf16fbdad2c6ef",
"sha256": "2d0c5ccc2e3971ce2009baef8995664f552f28a9fa10a59f03553d9739194842"
},
"downloads": -1,
"filename": "diffcord-1.0.2.tar.gz",
"has_sig": false,
"md5_digest": "c1a9579e473bab0176cf16fbdad2c6ef",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7.0",
"size": 7773,
"upload_time": "2023-05-09T20:08:14",
"upload_time_iso_8601": "2023-05-09T20:08:14.731711Z",
"url": "https://files.pythonhosted.org/packages/1e/7c/2708f367e1efd05516f5ac942acb7bdfbc31efe7782ff175deb425521019/diffcord-1.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-09 20:08:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "diff-cord",
"github_project": "python-sdk",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "diffcord"
}