How to use the discord.ext.commands.cooldown function in discord

To help you get started, we’ve selected a few discord examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PythonistaGuild / Wavelink / examples / advanced / advanced.py View on Github external
    @commands.cooldown(3, 30, commands.BucketType.guild)
    async def stop_(self, ctx):
        """Stop the player, disconnect and clear the queue.
        Examples
        ----------
        stop
            {ctx.prefix}stop
        """
        player = self.bot.wavelink.get_player(ctx.guild.id, cls=Player)

        if not player.is_connected:
            return await ctx.send('I am not currently connected to voice!')

        if await self.has_perms(ctx, manage_guild=True):
            await ctx.send(f'{ctx.author.mention} has stopped the player as an admin or DJ.', delete_after=25)
            return await self.do_stop(ctx)
github NabDev / NabBot / cogs / roles.py View on Github external
    @commands.cooldown(1, 5, commands.BucketType.user)
    async def group_add(self, ctx: NabCtx, *, name: str):
        """Creates a new group for members to join.

        The group can be a new role that will be created with this command.
        If the name matches an existent role, that role will become joinable.

        You need `Manage Roles` permissions to use this command."""
        name = name.replace("\"", "")
        forbidden = ["add", "remove", "delete", "list"]
        converter = InsensitiveRole()
        try:
            role = await converter.convert(ctx, name)
        except commands.BadArgument:
            try:
                if name.lower() in forbidden:
                    raise discord.InvalidArgument()
github Magic-Bots / xenon / xenon / cogs / builder.py View on Github external
    @cmd.cooldown(1, 5 * 60, cmd.BucketType.guild)
    async def build(self, ctx):
        """
        Choose between different options and build your discord server in less than a minute
        Enable and disable options by clicking the associated number and change the page
        by clicking the arrows. Click on the check to start the build process.


        __Examples__

        ```{c.prefix}build```
        """
        menu = BuildMenu(ctx)
        reason = f"Built by {ctx.author}"
        options = await menu.run()

        if options["delete_old_channels"] or options["delete_old_roles"]:
github NotSoSuper / NotSoBot / mods / Wc.py View on Github external
	@commands.cooldown(10, 1)
	async def wc_user(self, ctx, user:discord.User, max_messages:int=500):
		if max_messages > 4000 or max_messages < 1:
			max_messages = 500
		x = await self.bot.say("ok, processing{0}".format(' (this might take a while)' if max_messages > 2000 else ''))				
		text = await self.get_messages(ctx.message.channel, max_messages, user=user.id)
		b = await self.bot.loop.run_in_executor(None, self.make_wc, text, max_messages)
		await self.bot.upload(b, filename='wordcloud.png')
		await self.bot.delete_message(x)
github sx4-discord-bot / Sx4-Python / Sx4 / cogs / fun.py View on Github external
    @commands.cooldown(1, 3, commands.BucketType.user)
    async def convert(self, ctx, amount: float, currency_from: str, currency_to: str):
        request = requests.get("https://free.currencyconverterapi.com/api/v6/convert?q={}_{}&apiKey=4a355639d6e2e3ab32c6".format(currency_from.upper(), currency_to.upper())).json()
        if request["query"]["count"] == 0:
            return await ctx.send("Invalid currency :no_entry:")
        else:
            result = request["results"]["{}_{}".format(currency_from.upper(), currency_to.upper())]
            currency = format(result["val"] * amount, ".2f")
            amount = format(amount, ".2f")
            await ctx.send("**{}** {} \➡ **{}** {}".format(amount, currency_from.upper(), currency, currency_to.upper()))
github Maselkov / GW2Bot / guildwars2 / account.py View on Github external
    @commands.cooldown(1, 5, BucketType.user)
    async def search(self, ctx, *, item):
        """Find items on your account
        Required permissions: inventories, characters
        """
        if not self.can_embed_links(ctx):
            return await ctx.send("Need permission to embed links")
        user = ctx.author
        try:
            doc = await self.fetch_key(user, ["inventories", "characters"])
        except APIError as e:
            await self.error_handler(ctx, e)
        choice = await self.itemname_to_id(ctx,
                                           item,
                                           user,
                                           group_duplicates=True)
        if not choice:
github pawbot-discord / Pawbot / cogs / economy.py View on Github external
    @commands.cooldown(rate=1, per=10.0, type=commands.BucketType.user)
    async def leaderboard(self, ctx):
        """Shows global leaderboard"""
        query = "SELECT * FROM userbal ORDER BY money DESC LIMIT 3;"
        row = await self.bot.db.fetch(query)
        embed = discord.Embed(
            title="The Richest People",
            color=random.randint(0x000000, 0xFFFFFF),
            timestamp=ctx.message.created_at,
        )
        embed.add_field(
            name="**:dizzy: Leaders**",
            value=f""":first_place: | {self.bot.get_user(row[0][0])}: **{row[0][1]}** <:coins:529700967097171969>\n:second_place: | {self.bot.get_user(row[1][0])}: **{row[1][1]}** <:coins:529700967097171969>\n:third_place: | {self.bot.get_user(row[2][0])}: **{row[2][1]}** <:coins:529700967097171969>""",
        )
        embed.set_footer(
            text=f"These stats are global, {ctx.author.name}",
            icon_url=ctx.author.avatar_url,
github Godavaru / Godavaru / cogs / opts.py View on Github external
    @commands.cooldown(30, 1, commands.BucketType.guild)
    @commands.check(can_manage)
    async def logs(self, ctx, channel: str):
        """Change the guild logging channel.
        Note: To use this command, you must have the `MANAGE_GUILD` permission."""
        c = resolve_channel(channel, ctx)
        if c:
            self.bot.query_db(f'''INSERT INTO settings (guildid,log_channel) VALUES ({ctx.guild.id},{c.id})
                                ON DUPLICATE KEY UPDATE log_channel={c.id};''')
            await ctx.send(
                resolve_emoji('SUCCESS', ctx) + f' Successfully changed the logging channel to **#{c}** (`{c.id}`)')
        elif channel == 'reset':
            self.bot.query_db(f'''UPDATE settings SET log_channel=NULL WHERE guildid={ctx.guild.id};''')
            await ctx.send(resolve_emoji('SUCCESS', ctx) + ' Successfully reset your log channel.')
        else:
            await ctx.send(resolve_emoji('ERROR', ctx) + f' Channel "{channel}" not found.')
github FRCDiscord / Dozer / dozer / cogs / info.py View on Github external
    @cooldown(1, 10, BucketType.channel)
    @command(aliases=['server', 'guildinfo', 'serverinfo'])
    async def guild(self, ctx):
        """Retrieve information about this guild."""
        guild = ctx.guild
        static_emoji = sum(not e.animated for e in ctx.guild.emojis)
        animated_emoji = sum(e.animated for e in ctx.guild.emojis)
        e = discord.Embed(color=blurple)
        e.set_thumbnail(url=guild.icon_url)
        e.add_field(name='Name', value=guild.name)
        e.add_field(name='ID', value=guild.id)
        e.add_field(name='Created at', value=guild.created_at.strftime(datetime_format))
        e.add_field(name='Owner', value=guild.owner)
        e.add_field(name='Members', value=guild.member_count)
        e.add_field(name='Channels', value=str(len(guild.channels)))
        e.add_field(name='Roles', value=str(len(guild.roles) - 1))  # Remove @everyone
        e.add_field(name='Emoji', value="{} static, {} animated".format(static_emoji, animated_emoji))
github Run1e / AceBot / cogs / spotify.py View on Github external
	@commands.cooldown(3, 10.0, commands.BucketType.user)
	async def playing(self, ctx):
		'''Show us what you're listening to!'''

		track = await self._get_playing(ctx.author)

		if track is None:
			raise commands.CommandError('You don\'t seem to be playing anything.')

		artist = await self.sp.get_artist(track.artists[0].id)
		if artist is None:
			return

		e = self._craft_track_embed(artist, track)
		await ctx.send(embed=e)