Это класс команд.
Код: Выделить всё
from discord.ext import commands
from main import db
from scr.phrases_func import dict_to_str
from scr.cfg import phrases
from scr.command_author_check import command_author_check
class GeneralCommands(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.command()
async def info(self, ctx):
auth = ctx.message.author
if db.check_user(auth):
if db.get_user(auth).permissions_level >= 20:
await auth.send(ctx.message.author.mention + phrases.master_greeting + dict_to_str(phrases.master_commands))
else:
await auth.send(ctx.message.author.mention + phrases.slaves_greeting + dict_to_str(phrases.slaves_commands))
else:
await auth.send(ctx.message.author.mention + phrases.general_greeting + dict_to_str(phrases.slaves_commands))
@commands.command()
@command_author_check()
async def test(self, ctx):
await ctx.send("ПОЛУЧИЛОСЬ")
async def setup(bot: commands.Bot):
await bot.add_cog(GeneralCommands(bot))
Код: Выделить всё
from main import db
from scr.cfg import phrases
from scr import phrases_func
def command_author_check(permissions_level: int = 1):
print("command_author_check")
def decorator(func):
print("decorator")
async def wrapper(ctx, *args, **kwargs):
print("wrapper")
auth = ctx.message.author
if db.check_user(auth):
if db.get_user(auth).permissions_level >= permissions_level:
return await func(ctx, *args, **kwargs)
else:
await auth.send(ctx.message.author.mention + phrases.slaves_greeting + phrases_func.dict_to_str(phrases.slaves_commands))
else:
await auth.send(ctx.message.author.mention + phrases.general_greeting + phrases_func.dict_to_str(phrases.slaves_commands))
return wrapper
return decorator
Подробнее здесь: https://stackoverflow.com/questions/786 ... y-commands