import logging import dislash import lib import discord from discord.ext import commands from dislash import Option, OptionType, slash_command class General(commands.Cog): def __init__(self, bot): self.bot = bot # defining bot as global var in class @commands.Cog.listener() # this is a decorator for events/listeners async def on_ready(self): for g in self.bot.get_all_members(): lib.DB.prepare_db(g.guild.id) for g in self.bot.get_all_members(): lib.DB.fill_bd(g.name, g.id, g.bot, g.nick, g.guild.id) logging.info(f'Cog {__name__.split(".")[1]} is ready!.') @slash_command( name="info", description="Read list of tracks for user", options=[ Option("user", "Specify any user", OptionType.USER), ] ) async def info(self, ctx, user=None): user = user or ctx.author audio = lib.DB.read_db(ctx.guild.id, user.id) rolelist = [r.mention for r in user.roles if r != ctx.guild.default_role] if rolelist: roles = "\n".join(rolelist) else: roles = "Not added any role" if audio is None: audios = "Not selected audio" else: audios = "• " + "\n• ".join(sorted(audio.split(", "))) emb = discord.Embed( title=f"General information", description=f"General information on server about {user}", icon=user.avatar_url ) emb.set_thumbnail(url=user.avatar_url) emb.add_field(name="General info", value=f"Username: {user}\n" f"Nickname: {user.nick}\n" f"Joined at: {user.joined_at.strftime('%A, %B %d %Y @ %H:%M:%S')}", inline=False) emb.add_field(name="Audio list", value=f"{audios}", inline=True) emb.add_field(name="Roles list", value=f"{roles}", inline=True) emb.set_footer(text="Information requested by: {}".format(ctx.author.display_name)) await ctx.reply(embed=emb, ephemeral=True) @slash_command( name="set_guest_role", description="Set Default bot role", options=[ Option("role", "Specify role", OptionType.ROLE, required=True), ] ) @commands.has_permissions(administrator=True) async def set_guest_role(self, ctx, role): await lib.Commands.write_json(ctx.guild.id, "guest_role", role.id) await ctx.send(f"Setted up dsss bot role to: `{role.name}`", ephemeral=True) @commands.command(name="set_prefix") @commands.has_permissions(administrator=True) async def command_set_prefix(self, ctx, prefix: str): await lib.Commands.set_prefix(ctx, prefix) @slash_command( name="set_prefix", description="Setting up bot prefix", options=[ Option("prefix", "Specify prefix", OptionType.STRING, required=True), ] ) @dislash.has_permissions(administrator=True) async def slash_set_prefix(self, ctx, prefix: str): await lib.Commands.set_prefix(ctx, prefix) @slash_set_prefix.error @command_set_prefix.error async def set_prefix_error(self, ctx, prefix): await ctx.reply('You don`t have permissions', ephemeral=True) @slash_command( name="set_trigger_role", description="Setting up role to trigger bot", options=[ Option("role", "Specify role", OptionType.ROLE, required=True), ] ) @commands.has_permissions(administrator=True) async def set_trigger_role(self, ctx, role): await lib.Commands.write_json(ctx.guild.id, "tigger_role", role.id) await ctx.send(f"Role to trigger set to : `{role.name}`", ephemeral=True) @slash_command( name="set_bot_role", description="Set Default bot role", options=[ Option("role", "Specify role", OptionType.ROLE, required=True), ] ) @dislash.has_permissions(administrator=True) async def set_bot_role(self, ctx, role): await lib.Commands.write_json(ctx.guild.id, "bot_role", role.id) await ctx.send(f"Setted up bot role to: `{role.name}`", ephemeral=True) def setup(bot): # an extension must have a setup function bot.add_cog(General(bot)) # adding a cog