Python discord.ext.commands.MissingPermissions() Examples
The following are 17
code examples of discord.ext.commands.MissingPermissions().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
discord.ext.commands
, or try the search function
.
Example #1
Source File: bot.py From RemixBot with MIT License | 6 votes |
def on_command_error(ctx, error): send_help = (commands.MissingRequiredArgument, commands.BadArgument, commands.TooManyArguments, commands.UserInputError) if isinstance(error, commands.CommandNotFound): # fails silently pass elif isinstance(error, send_help): _help = await send_cmd_help(ctx) await ctx.send(embed=_help) elif isinstance(error, commands.CommandOnCooldown): await ctx.send(f'This command is on cooldown. Please wait {error.retry_after:.2f}s') elif isinstance(error, commands.MissingPermissions): await ctx.send('You do not have the permissions to use this command.') # If any other error occurs, prints to console. else: print(''.join(traceback.format_exception(type(error), error, error.__traceback__)))
Example #2
Source File: locale.py From EmoteCollector with GNU Affero General Public License v3.0 | 6 votes |
def set_locale_command(self, context, channel: typing.Optional[discord.TextChannel], locale: Locale): """Set the locale for a channel or yourself. Manage Messages is required to change the locale of a whole channel. If the channel is left blank, this command sets your user locale. """ if channel is None: await self.set_user_locale(context.author.id, locale) elif ( not context.author.guild_permissions.manage_messages or not await self.bot.is_owner(context.author) ): raise commands.MissingPermissions(('manage_messages',)) else: await self.set_channel_locale(context.guild.id, channel.id, locale) await context.try_add_reaction(utils.SUCCESS_EMOJIS[True])
Example #3
Source File: checks.py From NabBot with Apache License 2.0 | 6 votes |
def has_guild_permissions(**perms): """Command can only be used if the user has the provided guild permissions.""" def predicate(ctx): if ctx.guild is None: raise commands.NoPrivateMessage("This command cannot be used in private messages.") permissions = ctx.author.guild_permissions missing = [perm for perm, value in perms.items() if getattr(permissions, perm, None) != value] if not missing: return True raise commands.MissingPermissions(missing) return commands.check(predicate) # endregion # region Auxiliary functions (Not valid decorators)
Example #4
Source File: base.py From bot with MIT License | 6 votes |
def assertHasPermissionsCheck( # noqa: N802 self, cmd: commands.Command, permissions: Dict[str, bool], ) -> None: """ Test that `cmd` raises a `MissingPermissions` exception if author lacks `permissions`. Every permission in `permissions` is expected to be reported as missing. In other words, do not include permissions which should not raise an exception along with those which should. """ # Invert permission values because it's more intuitive to pass to this assertion the same # permissions as those given to the check decorator. permissions = {k: not v for k, v in permissions.items()} ctx = helpers.MockContext() ctx.channel.permissions_for.return_value = discord.Permissions(**permissions) with self.assertRaises(commands.MissingPermissions) as cm: await cmd.can_run(ctx) self.assertCountEqual(permissions.keys(), cm.exception.missing_perms)
Example #5
Source File: main.py From RulesBot with MIT License | 6 votes |
def on_command_error(ctx: commands.Context, exc: BaseException): if isinstance(exc, ignore_errors): pass elif isinstance(exc, MissingPermissions): await ctx.send( embed=Embed( description='YAdmin command executed', color=Color.red())) elif isinstance(exc, NotADeveloper): await ctx.send( embed=Embed( description='Oh nice you found an dev only command, but sorry only for devs!', color=Color.red())) else: raise exc
Example #6
Source File: core.py From NabBot with Apache License 2.0 | 5 votes |
def process_check_failure(cls, ctx: context.NabCtx, error: commands.CheckFailure): """Handles CheckFailure errors. These are exceptions that may be raised when executing command checks.""" if isinstance(error, (commands.NoPrivateMessage, errors.NotTracking, errors.UnathorizedUser, commands.MissingPermissions)): await ctx.error(error) elif isinstance(error, errors.CannotEmbed): await ctx.error(f"Sorry, `Embed Links` permission is required for this command.")
Example #7
Source File: bot.py From Dozer with GNU General Public License v3.0 | 5 votes |
def on_command_error(self, context, exception): if isinstance(exception, commands.NoPrivateMessage): await context.send('{}, This command cannot be used in DMs.'.format(context.author.mention)) elif isinstance(exception, commands.UserInputError): await context.send('{}, {}'.format(context.author.mention, self.format_error(context, exception))) elif isinstance(exception, commands.NotOwner): await context.send('{}, {}'.format(context.author.mention, exception.args[0])) elif isinstance(exception, commands.MissingPermissions): permission_names = [name.replace('guild', 'server').replace('_', ' ').title() for name in exception.missing_perms] await context.send('{}, you need {} permissions to run this command!'.format( context.author.mention, utils.pretty_concat(permission_names))) elif isinstance(exception, commands.BotMissingPermissions): permission_names = [name.replace('guild', 'server').replace('_', ' ').title() for name in exception.missing_perms] await context.send('{}, I need {} permissions to run this command!'.format( context.author.mention, utils.pretty_concat(permission_names))) elif isinstance(exception, commands.CommandOnCooldown): await context.send( '{}, That command is on cooldown! Try again in {:.2f}s!'.format(context.author.mention, exception.retry_after)) elif isinstance(exception, (commands.CommandNotFound, InvalidContext)): pass # Silent ignore else: await context.send('```\n%s\n```' % ''.join(traceback.format_exception_only(type(exception), exception)).strip()) if isinstance(context.channel, discord.TextChannel): DOZER_LOGGER.error('Error in command <%d> (%d.name!r(%d.id) %d(%d.id) %d(%d.id) %d)', context.command, context.guild, context.guild, context.channel, context.channel, context.author, context.author, context.message.content) else: DOZER_LOGGER.error('Error in command <%d> (DM %d(%d.id) %d)', context.command, context.channel.recipient, context.channel.recipient, context.message.content) DOZER_LOGGER.error(''.join(traceback.format_exception(type(exception), exception, exception.__traceback__)))
Example #8
Source File: queue.py From csgo-queue-bot with GNU General Public License v3.0 | 5 votes |
def cap_error(self, ctx, error): """ Respond to a permissions error with an explanation message. """ if isinstance(error, commands.MissingPermissions): await ctx.trigger_typing() missing_perm = error.missing_perms[0].replace('_', ' ') title = f'Cannot change queue capacity without {missing_perm} permission!' embed = discord.Embed(title=title, color=self.color) await ctx.send(embed=embed)
Example #9
Source File: queue.py From csgo-queue-bot with GNU General Public License v3.0 | 5 votes |
def remove_error(self, ctx, error): """ Respond to a permissions error with an explanation message. """ if isinstance(error, commands.MissingPermissions): await ctx.trigger_typing() missing_perm = error.missing_perms[0].replace('_', ' ') title = f'Cannot remove players without {missing_perm} permission!' embed = discord.Embed(title=title, color=self.color) await ctx.send(embed=embed)
Example #10
Source File: mapdraft.py From csgo-queue-bot with GNU General Public License v3.0 | 5 votes |
def setmp_error(self, ctx, error): """ Respond to a permissions error with an explanation message. """ if isinstance(error, commands.MissingPermissions): await ctx.trigger_typing() missing_perm = error.missing_perms[0].replace('_', ' ') title = f'Cannot set the map pool without {missing_perm} permission!' embed = discord.Embed(title=title, color=self.color) await ctx.send(embed=embed)
Example #11
Source File: pollmaster.py From pollmaster with MIT License | 5 votes |
def on_command_error(ctx, e): if hasattr(ctx.cog, 'qualified_name') and ctx.cog.qualified_name == "Admin": # Admin cog handles the errors locally return if SETTINGS.log_errors: ignored_exceptions = ( commands.MissingRequiredArgument, commands.CommandNotFound, commands.DisabledCommand, commands.BadArgument, commands.NoPrivateMessage, commands.CheckFailure, commands.CommandOnCooldown, commands.MissingPermissions, discord.errors.Forbidden, ) if isinstance(e, ignored_exceptions): # log warnings # logger.warning(f'{type(e).__name__}: {e}\n{"".join(traceback.format_tb(e.__traceback__))}') return # log error logger.error(f'{type(e).__name__}: {e}\n{"".join(traceback.format_tb(e.__traceback__))}') traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr) if SETTINGS.msg_errors: # send discord message for unexpected errors e = discord.Embed( title=f"Error With command: {ctx.command.name}", description=f"```py\n{type(e).__name__}: {str(e)}\n```\n\nContent:{ctx.message.content}" f"\n\tServer: {ctx.message.server}\n\tChannel: <#{ctx.message.channel}>" f"\n\tAuthor: <@{ctx.message.author}>", timestamp=ctx.message.timestamp ) await ctx.send(bot.owner, embed=e) # if SETTINGS.mode == 'development': raise e
Example #12
Source File: checks.py From RulesBot with MIT License | 5 votes |
def admin_permissions(): def predicate(ctx: CommandContext): author: Member = ctx.message.author if author.id in ADMINS: return True elif not author.guild_permissions.administrator: raise MissingPermissions("You are missing administrator permissions") else: return True return commands.check(predicate)
Example #13
Source File: checks.py From NabBot with Apache License 2.0 | 5 votes |
def has_permissions(**perms): """Command can only be used if the user has the provided permissions.""" async def pred(ctx): ret = await check_permissions(ctx, perms) if not ret: raise commands.MissingPermissions(perms) return True return commands.check(pred)
Example #14
Source File: utils.py From RemixBot with MIT License | 5 votes |
def developer(): def wrapper(ctx): with open('data/devs.json') as f: devs = json.load(f) if ctx.author.id in devs: return True raise commands.MissingPermissions('You cannot use this command because you are not a developer.') return commands.check(wrapper)
Example #15
Source File: nullctf.py From NullCTF with GNU General Public License v3.0 | 5 votes |
def on_command_error(ctx, error): if isinstance(error, commands.CommandNotFound): return if isinstance(error, commands.MissingRequiredArgument): await ctx.send("Missing a required argument. Do >help") if isinstance(error, commands.MissingPermissions): await ctx.send("You do not have the appropriate permissions to run this command.") if isinstance(error, commands.BotMissingPermissions): await ctx.send("I don't have sufficient permissions!") else: print("error not caught") print(error)
Example #16
Source File: configuration.py From modmail with GNU Affero General Public License v3.0 | 5 votes |
def prefix(self, ctx, *, prefix: str = None): if prefix is None: await ctx.send( embed=discord.Embed( description=f"The prefix for this server is `{ctx.prefix}`.", colour=self.bot.primary_colour, ) ) return if ctx.author.guild_permissions.administrator is False: raise commands.MissingPermissions(["administrator"]) else: if len(prefix) > 10: await ctx.send( embed=discord.Embed(description="The chosen prefix is too long.", colour=self.bot.error_colour,) ) return if prefix == self.bot.config.default_prefix: prefix = None await self.bot.get_data(ctx.guild.id) async with self.bot.pool.acquire() as conn: await conn.execute("UPDATE data SET prefix=$1 WHERE guild=$2", prefix, ctx.guild.id) self.bot.all_prefix[ctx.guild.id] = prefix await ctx.send( embed=discord.Embed( description="Successfully changed the prefix to " f"`{self.bot.config.default_prefix if prefix is None else prefix}`.", colour=self.bot.primary_colour, ) )
Example #17
Source File: handler.py From DJ5n4k3 with MIT License | 4 votes |
def on_command_error(self, ctx, error): if hasattr(ctx.command, 'on_error'): return ignored = (commands.MissingRequiredArgument, commands.BadArgument, commands.NoPrivateMessage, commands.CheckFailure, commands.CommandNotFound, commands.DisabledCommand, commands.CommandInvokeError, commands.TooManyArguments, commands.UserInputError, commands.CommandOnCooldown, commands.NotOwner, commands.MissingPermissions, commands.BotMissingPermissions) error = getattr(error, 'original', error) if isinstance(error, commands.CommandNotFound): return elif isinstance(error, commands.BadArgument): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.MissingRequiredArgument): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.NoPrivateMessage): return elif isinstance(error, commands.CheckFailure): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like this command is thought for other users. You can't use it.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.DisabledCommand): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like this command in disabled.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.CommandInvokeError): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like something went wrong. Report this issue to the developer.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.TooManyArguments): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like you gave too many arguments.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.UserInputError): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like you did something wrong.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.CommandOnCooldown): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.NotOwner): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like you do not own this bot.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.MissingPermissions): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url)) elif isinstance(error, commands.BotMissingPermissions): await ctx.send(embed=discord.Embed(color=self.bot.color).set_footer(text=f"Seems like {error}.", icon_url=ctx.author.avatar_url))