How to use the discord.ext.commands.has_permissions function in discord

To help you get started, we’ve selected a few discord examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Roxxers / roxbot / roxbot / cogs / reddit.py View on Github external
    @commands.has_permissions(add_reactions=True)
    @commands.bot_has_permissions(add_reactions=True)
    async def subreddit(self, ctx, subreddit):
        """
        Grabs an image or video (jpg, png, gif, gifv, webm, mp4) from the subreddit inputted.
        Example:
        {command_prefix}subreddit pics
        """
        subreddit = subreddit.lower()
        if isinstance(ctx.channel, discord.DMChannel):
            cache_id = ctx.author.id
            nsfw_allowed = True
        else:  # Is text channel in guild
            cache_id = ctx.guild.id
            nsfw_allowed = ctx.channel.is_nsfw()

        self.scrapper.cache_refresh(cache_id)
github DXsmiley / mathbot / mathbot / modules / settings.py View on Github external
	@has_permissions(administrator=True)
	async def setprefix(self, ctx, *, new_prefix):
		prefix = new_prefix.strip().replace('`', '')
		await ctx.bot.settings.set_server_prefix(ctx.guild, prefix)
		await ctx.send(f'Bot prefix for this server has been changed to `{prefix}`.')
github PapyrusThePlant / Scarecrow / cogs / prefix.py View on Github external
    @commands.has_permissions(manage_guild=True)
    async def prefix_group(self, ctx):
        pass
github MonikaDiscord / Monika / cogs / mod.py View on Github external
    @commands.has_permissions(manage_messages = True)
    async def prune(self, ctx, number: int):
        """Deletes the specified number of messages."""

        if ctx.invoked_subcommand is None:
            channel = ctx.message.channel
            author = ctx.message.author
            server = author.guild
            has_permissions = channel.permissions_for(server.me).manage_messages

            to_delete = []

            if not has_permissions:
                await ctx.send("I can't delete messages...")
                return

            async for message in channel.history(limit=number+1):
github Roxxers / roxbot / roxbot / cogs / voice.py View on Github external
    @commands.has_permissions(manage_channels=True)
    @commands.command()
    async def voice(self, ctx, setting=None, change=None):
        """Edits settings for the voice cog.

        Options:
            - `enable/disable`: Enable/disables specified change.
            - `skipratio`: Specify what the ratio should be for skip voting if enabled. Example: 0.6 for 60%
            - `maxlength/duration`: Specify (in seconds) the max duration of a video that can be played.

        Possible settings to enable/disable:
            - `needperms`: specifies whether `volume`, `pause`, or `resume` require permissions or not.
            - `skipvoting`: enables voting to skip instead of one user skipping.

        Example:
            # Enable skipvoting
            ;voice enable skip_voting
github EvieePy / EvieeBot / modules / moderation.py View on Github external
    @commands.has_permissions(manage_messages=True)
    async def do_cleanup(self, ctx, limit: int=20):
        """Cleanup a bot sessions messages.

        !Manage Messages is required to run this command fully!

        Parameters
        ------------
        limit: int [Optional]
            The max amount of messages to try and clean. This defaults to 20.

        Examples
        ----------
        cleanup 

            {ctx.prefix}cleanup 30
            {ctx.prefix}cleanup
github MonikaDiscord / Monika / cogs / mod.py View on Github external
    @commands.has_permissions(kick_members=True)
    async def kick(self, ctx, user: discord.User, *, reason=None):
        """Kicks a user."""
        try:
            await ctx.message.guild.kick(user, reason=reason)
        except Exception:
            self.bot.rclient.captureException()
            await ctx.send("I couldn't do that for you... I'm so sorry!")
            return
        await ctx.send("I kicked " + str(user) + " for you, <@{}>~".format(ctx.message.author.id))
github FRCDiscord / Dozer / dozer / cogs / moderationstrformatted.py View on Github external
    @has_permissions(ban_members=True)
    @bot_has_permissions(ban_members=True)
    async def unban(self, ctx, user_mentions: discord.User, *, reason):
        "Unbans the user ID mentioned."
        usertoban = user_mentions
        usertobanstr = str(usertoban)
        await ctx.guild.unban(usertoban)
        modlogmessage = str("{} has been unbanned by {} because {}").format(usertobanstr, ctx.author.mention, reason)
        await ctx.send(modlogmessage)
        with db.Session() as session:
            modlogchannel = session.query(Guildmodlog).filter_by(id=ctx.guild.id).one_or_none()
            if modlogchannel is not None:
                channel = ctx.guild.get_channel(modlogchannel.modlog_channel)
                await channel.send(modlogmessage)
            else:
                await ctx.send("Please configure modlog channel to enable modlog functionality")
github Godavaru / Godavaru / cogs / mod.py View on Github external
    @commands.has_permissions(ban_members=True)
    @commands.bot_has_permissions(ban_members=True)
    async def softban(self, ctx, member: discord.Member, *, reason: str = None):
        """Kick a member from the guild and clean messages from the last 7 days.
        You can also supply an optional reason.
        Add `--delete-days ` to the end to add an amount of days to delete."""
        if ctx.author.top_role.position > member.top_role.position:
            days = 7
            flags = parse_flags(reason)
            if flags.get('delete-days'):
                try:
                    days = int(flags.get('delete-days'))
                except ValueError:
                    days = 7
            if days > 7:
                days = 7
            if days < 0: