示例#1
0
 async def guild_roles(self, ctx):
     """Returns all the existing roles in the current guild."""
     e = Embed()
     e.add_field(name="\uFEFF",
                 value=[", ".join(r.mention for r in [*ctx.guild.roles])])
     e.color = color.invis(self)
     await ctx.send(embed=e)
示例#2
0
    async def _warn_info(self, ctx, *, warn_id: str):
        """
        info about a warn by its ID
        if you don't know the warm id just type warns @member
        """
        if not warn_id:
            await ctx.send("No warn id was provided.")

        else:
            found = await self.bot.pool.fetch(
                "SELECT * FROM warns WHERE warn_id = $1 AND guild_id = $2",
                warn_id,
                ctx.guild.id,
            )
            if found:
                for warn in found:

                    reason = "".join(map(str, warn["reason"]))
                    warn_id = "".join(map(str, warn["warn_id"]))
                    member_id = f'<@{warn["member_id"]}>'
                    author_id = f'<@{warn["author_id"]}>'

                    e = Embed(
                        color=color.invis(self),
                        description=f"Warn info for {member_id}",
                    )
                    e.add_field(name="Warn ID", value=warn_id)
                    e.add_field(name="Warned by", value=author_id, inline=True)
                    e.add_field(name="Reason", value=reason, inline=False)
                    e.add_field(name="Warned at", value=warn["warned_at"])
                    await ctx.send(embed=e)
            else:
                await ctx.send("No warns found.")
示例#3
0
    async def define(self, ctx, *, word: str):
        try:
            resp = await ctx.http.get(
                "https://mashape-community-urban-dictionary.p.rapidapi.com/define",
                headers={
                    "x-rapidapi-key": config.rapid_api,
                    "x-rapidapi-host": "mashape-community-urban-dictionary.p.rapidapi.com",
                },
                params={"term": word.lower()},
            )

            coro = await resp.json()

            define = random.choice(coro.get("list"))
            ex: str = str(define.get("example", None))
            real: str = str(define.get("definition", None))
            vots: int = define.get("thumbs_up", 0)
            votedown: int = define.get("thumbs_down", 0)
            date: datetime.datetime = define.get("written_on")
            url: str = define.get("permalink", None)
            author: str = define.get("author")

            e = discord.Embed(
                title=f"ThumbsUp ```{vots}``` | ThumbsDown ```{votedown}```",
                description=real.replace("[", "").replace("]", ""),
                color=color.invis(self),
            )
            e.add_field(name="Example", value=ex.replace("[", "").replace("]", ""))
            e.set_author(name=author, url=url)
            e.set_footer(text=date)
            await ctx.send(embed=e)
        except IndexError:
            return await ctx.send("Didn't find anything.")
示例#4
0
    async def _tag_info(self, ctx, *, tag):
        """returns info about a specific tag."""

        found = await ctx.pool.fetchrow(
            """
            SELECT tag_name, tag_owner, created_at, tag_id 
            FROM tags 
            WHERE tag_name = $1 AND guild_id = $2
            """,
            tag,
            ctx.guild.id,
        )
        if found:
            name = found["tag_name"]
            owner = f'<@{found["tag_owner"]}>'
            created_at = found["created_at"]
            tag_id = found["tag_id"]

            e = Embed(title=f"Info about {tag}", color=color.invis(self))
            e.add_field(name="Name", value=name)
            e.add_field(name="Owner", value=owner)
            e.add_field(name="ID", value=tag_id)
            e.add_field(name="Created At", value=created_at)
            await ctx.send(embed=e)
        else:
            await ctx.send("Tag not found.")
示例#5
0
    async def on_command_error(self, ctx: Context, err) -> None:
        if isinstance(err, commands.NoPrivateMessage):
            await ctx.author.send("This command cannot be used in private messages.")

        elif isinstance(err, commands.BotMissingPermissions):
            embed = discord.Embed(
                title=f"I don't have permissions to do that.", colour=color.invis(self)
            )
            await ctx.send(embed=embed)

        elif isinstance(err, commands.CommandInvokeError):
            original = err.original
            if not isinstance(original, discord.HTTPException):
                _LOG.error(f"In {ctx.command.qualified_name}:", file=sys.stderr)
                traceback.print_tb(original.__traceback__)
                _LOG.error(
                    f"{original.__class__.__name__}: {original}", file=sys.stderr
                )

        elif isinstance(err, commands.CommandOnCooldown):
            embed = discord.Embed(
                title="This command is on cooldown.", colour=color.invis(self)
            )
            await ctx.send(embed=embed)
示例#6
0
    async def color_cmd(self, ctx, *, color=None) -> None:
        """
        Returns a human readble color by its name.

        Examples:
        ```color blue```
        ```color red```
        ```color violet```
        ```color indigo```
        """
        e = Embed(title=colour.Color(color).hex, color=c.invis(self))
        e.set_image(url=self.api.view_color(colour.Color(color).hex))
        try:
            await ctx.send(embed=e)
        except ValueError:
            pass
示例#7
0
 async def on_guild_remove(self, guild):
     roles = [role.mention for role in guild.roles]
     e = discord.Embed(title="Left a server!",
                       color=color.invis(self),
                       timestamp=datetime.utcnow())
     e.add_field(name="Server name", value=guild.name)
     e.add_field(name="Server ID", value=guild.id)
     e.add_field(name="Server Owner", value=guild.owner)
     e.add_field(name="Members", value=guild.member_count)
     e.add_field(name="Server region", value=guild.region)
     e.add_field(name="Boosters", value=guild.premium_subscription_count)
     e.add_field(name="Boost Level", value=guild.premium_tier)
     e.add_field(
         name="Roles",
         value=", ".join(roles)
         if len(roles) < 20 else f"{len(roles)} roles",
     )
     e.set_thumbnail(url=guild.icon_url)
     chan = self.bot.get_channel(789614938247266305)
     await chan.send(embed=e)
示例#8
0
 async def warns(self, ctx, member: Union[Member, FetchedUser] = None):
     """
     Show a member's warns.
     You will need the admin or `manage_guild` perms to use this command.
     ```Usage: warns <member_id> or <member name> or <@member>```
     """
     member = member or ctx.author
     found = await self.bot.pool.fetch(
         "SELECT * FROM warns WHERE member_id = $1 AND guild_id = $2",
         member.id,
         ctx.guild.id,
     )
     if found:
         fmt = "\n".join(r["reason"] + " " + f"(ID: {r['warn_id']})"
                         for r in found)
         e = Embed(color=color.invis(self), description=fmt)
         e.set_author(name=member.display_name, icon_url=member.avatar)
         return await ctx.send(embed=e)
     else:
         return await ctx.send("No warns found.")