Skip to main content

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)

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")

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

diffcord-1.0.3.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

diffcord-1.0.3-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file diffcord-1.0.3.tar.gz.

File metadata

  • Download URL: diffcord-1.0.3.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

Hashes for diffcord-1.0.3.tar.gz
Algorithm Hash digest
SHA256 8574768e8bc844062b8a0efdd001eb412e3f4b74c7e39a64139f6638cbe9d3c9
MD5 3960905f48c4e8a4f0c05bcd869e06c1
BLAKE2b-256 555be4d0ab9c71306bd46deb32555de6ff991dda5a76097ab1bf966a1b4399b3

See more details on using hashes here.

File details

Details for the file diffcord-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: diffcord-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for diffcord-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5b877afd6e6278decad31e91c2d9a0eeae3a58c526db53cdd962e7dd3d0f1eea
MD5 5aee7ee354b41641590a352d6636ccc3
BLAKE2b-256 3c6939ddd7e63ceaec60de94ceae8e3497b1b8a1e37270bd65d37d0c2abddea2

See more details on using hashes here.

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