Coder Social home page Coder Social logo

modern-realm / discord_cooldown Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 0.0 89 KB

A responsive package for bot command cooldowns, with this package you can create the command cooldowns which will not get reset whenever the bot re-run

Home Page: https://pypi.org/project/discord-cooldown/

License: Other

Python 100.00%
cooldown cooldowns discord-py custom-cooldown disnake py-cord discord nextcord discord-cooldown python

discord_cooldown's Introduction

Package Name: discord_cooldown

A responsive package for Bot command cooldowns

• With this package you can create the command cooldowns which will not get reset whenever the bot re-run

forthebadge made-with-python

CodeQL Python Github License Windows Linux

GitHub stars GitHub forks GitHub issues

Join Official Discord Server for more guidance !


Features

  • Cooldowns of Bot commands are stored in a DATABASE
  • Available Databases MySQL, PostgreSQL and Sqlite(Sqlite3)

Installation

Python 3.8 or higher is required !

# Linux/macOS
  python3 -m pip install discord-cooldown

# Windows
  # Method-1:
    py -3 -m pip install discord-cooldown
    # or
    python -m pip install discord-cooldown
  # Method-2:
    pip install discord-cooldown

# Using GIT for ALPHA or BETA Versions
  # Method-1:
    pip install git+https://github.com/Modern-Realm/discord_cooldown
  # Method-2:
    pip install -U git+https://github.com/Modern-Realm/discord_cooldown

Note: For better stability install package from GitHub using GIT


REQUIRED DEPENDENCIES

You can use ANY ONE of the below discord API Package

Note: Don't install more than one DEPENDENCY !

Other Dependencies


QuickStart

To use discord_cooldown in cogs or multiple files, go through the template: cooldown-bot-template

from discord_cooldown import Cooldown, SQlite, MySQL, PostgreSQL

import discord

from datetime import timedelta
from discord.ext import commands
from os import getenv

token = getenv("TOKEN")
intents = discord.Intents.all()
client = commands.Bot(command_prefix="$", intents=intents)

# For Indian timezone (UTC +5:30)
timezone = +timedelta(hours=5, minutes=30)

# For sqlite
db = SQlite()

# For mysql
# db = MySQL(host=..., port=..., user=..., passwd=..., db_name=...)

# For postgresql
# db = PostgreSQL(host=..., port=..., user=..., passwd=..., db_name=...)

CD = Cooldown(db, timezone)


@client.event
async def on_ready():
    await client.change_presence(status=discord.Status.online, activity=discord.Game("$help"))
    print("Bot is online")


@client.event
async def on_application_command_error(ctx: discord.ApplicationContext, error):
    if isinstance(error, commands.CommandOnCooldown):
        return await ctx.respond(
            f"on cooldown retry after `{timedelta(seconds=error.retry_after)}`",
            ephemeral=True
        )

    else:
        # For resetting a command cooldown if any error occurred
        return await CD.reset_cooldown(ctx)


@client.event
async def on_command_error(ctx: commands.Context, error):
    if isinstance(error, commands.CommandOnCooldown):
        return await ctx.send(
            f"on cooldown retry after `{timedelta(seconds=error.retry_after)}`"
        )

    else:
        # For resetting a command cooldown if any error occurred
        return await CD.reset_cooldown(ctx)


@CD.cooldown(2, 1 * 60, type=commands.BucketType.channel)
@client.command()
async def test(ctx):
    await ctx.send("testing")


@CD.cooldown(1, reset_per_day=True, type=commands.BucketType.guild)
@client.command()
async def vote(ctx):
    await ctx.send("done")


@CD.cooldown(2, 60)
@client.command()
async def test1(ctx, msg: str):
    if msg is None:
        raise ValueError("msg is missing, cooldown not triggered")

    await ctx.send("message is " + msg)


if __name__ == "__main__":
    client.run(token)

Useful Links

You can get support/help/guidance from below social-media links

discord_cooldown's People

Contributors

skrphenix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.