Hello, I don't know if my problem is clear from the title, but you will understand with the code :
# file ./main.py
class ShardedBot(discord.AutoShardedBot):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
async def start(self, token: str, *, reconnect: bool = True):
await self.setup_database()
await self.setup_translator()
# Load cogs
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
bot.load_extension(f'cogs.{filename[:-3]}')
await self.login(token)
await self.connect(reconnect=reconnect)
async def setup_translator(self):
proxy = "PRIVATE"
self.trad = Translator(proxy=proxy)
print(f"=== Proxy Setup updated ! ===")
def translator_handler(self, func):
"""Decorator to handle translation and rate limiting errors."""
async def wrapper(*args, **kwargs):
try:
return await func(*args, **kwargs)
except RateLimitError:
await self.setup_translator()
try:
return await func(*args, **kwargs)
except RateLimitError:
raise RateLimitError("Rate limit error even after changing proxy.")
return wrapper
bot = ShardedBot()
# file ./cogs/message_translator.py
class MessageTranslator(Cog):
def __init__(self, bot):
self.bot = bot
@self.bot.translator_handler # self is not defined
@Cog.listener()
async def on_message(self, message):
# Some code here
I would like to use the decorator translator_handler from my main file in my cog. How can I do that ?