Last active
April 13, 2023 17:59
-
-
Save AwSkies/6128d89a1e842b4e802b3a077d7f98a5 to your computer and use it in GitHub Desktop.
commands with whitelisted cooldowns for discord.py rewrite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
from discord.ext import commands | |
from discord.ext.commands.cooldowns import BucketType | |
bot = commands.Bot(command_prefix = "your prefix here") | |
token = 'token goes here' | |
#on ready login message | |
@bot.event | |
async def on_ready(): | |
print('Logged in as {} - {}'.format(bot.user.name, bot.user.id)) | |
#rate: how many times the command can be used before triggering the cooldown | |
rate = 1 | |
#per: the amount of seconds the cooldown lasts | |
per = 10 | |
#type: the scope of the cooldown, go to https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.cooldown for more info | |
t = BucketType.default | |
#example command | |
@bot.command( | |
name = 'command', | |
description = 'example description', | |
) | |
#cooldown | |
@commands.cooldown(rate, per, t) | |
async def example_command(ctx): | |
#put your command things here | |
pass | |
#whitelist: the list of IDs of people/roles/channels/things to ignore | |
#to whitelist someone/something, add their ID to the whitelist | |
whitelist = [123456789, 987654321] | |
@example_command.after_invoke | |
async def reset_cooldown(ctx): | |
for e in whitelist: | |
#to whitelist a person: | |
if e == ctx.author.id: | |
example_command.reset_cooldown(ctx) | |
#to whitelist a channel: | |
if e == ctx.message.channel.id: | |
example_command.reset_cooldown(ctx) | |
#to whitelist a guild/server: | |
if e == ctx.message.guild.id: | |
example_command.reset_cooldown(ctx) | |
#to whitelist a role: | |
if e in [role.id for role in ctx.author.roles]: | |
example_command.reset_cooldown(ctx) | |
bot.run(token) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
from discord.ext import commands | |
from discord.ext.commands.cooldowns import BucketType | |
#rate: how many times the command can be used before triggering the cooldown | |
rate = 1 | |
#per: the amount of seconds the cooldown lasts | |
per = 10 | |
#type: the scope of the cooldown, go to https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.cooldown to see what they are | |
t = BucketType.default | |
class MyCog(commands.Cog): | |
def __init__(self, bot): | |
self.bot = bot | |
#whitelist: the list of IDs of people/roles/channels/things to ignore | |
#to whitelist someone/something, add their ID to the whitelist | |
self.whitelist = [123456789, 987654321] | |
#example command | |
@bot.command( | |
name = 'command', | |
description = 'example description', | |
) | |
#cooldown | |
@commands.cooldown(rate, per, t) | |
async def example_command(self, ctx): | |
#put your command things here | |
pass | |
@example_command.after_invoke | |
async def reset_cooldown(self, ctx): | |
for e in self.whitelist: | |
#to whitelist a person: | |
if e == ctx.author.id: | |
self.example_command.reset_cooldown(ctx) | |
#to whitelist a channel: | |
if e == ctx.message.channel.id: | |
self.example_command.reset_cooldown(ctx) | |
#to whitelist a guild/server: | |
if e == ctx.message.guild.id: | |
self.example_command.reset_cooldown(ctx) | |
#to whitelist a role: | |
if e in [role.id for role in ctx.author.roles]: | |
self.example_command.reset_cooldown(ctx) | |
#cog setup function | |
def setup(bot): | |
bot.add_cog(MyCog(bot)) |
@MrHitMan1 it means that only whitelisted people can bypass the cooldown.
hi, @CapClumsy mine doesnt work (command not found).
i change the command_prefix to "."
it should work if i type .pass right? because i set the prefix to "." and the #put your commands here to pass
@daffanovel12 Is the name of your command pass? The name of your command is specified by the name of the function or by the name
parameter in the @bot.command
decorator. The keyword pass
is just something used as example code to put in a command. My guess would be try using .command
or .example_command
. I may just be confused by your question however.
nvm, i missunderstood by the code. i thought its for bypass slowmode. sorry to bother
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
does the whitelist here mean that whitlisted people can bypass the cooldown or that only whitelisted people can use the command?