How to use the discord.ext.commands.BadArgument 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 Support-Manager / Discord-Bot / bot / commands / config.py View on Github external
try:
                    choice = await ctx.bot.wait_for('message', check=check, timeout=60)
                except asyncio.TimeoutError:
                    continue
                choice = choice.content

            if choice is None or choice == prefix + 'abort':
                await msg.edit(content=ctx.translate("configuration dialog closed"), embed=None)
                await msg.clear_reactions()
                break

            if converter is not None:
                try:
                    choice = await converter.convert(ctx, choice)  # convert string to specific Object (like Channel)
                except commands.BadArgument:
                    await ctx.send(ctx.translate("invalid input"))
                    continue

            command = ctx.bot.get_command('config ' + action)
            await ctx.invoke(command, choice)
github Roxxers / roxbot / roxbot / cogs / selfassign.py View on Github external
raise commands.BadArgument("Could not find that role.")
            except TransactionIntegrityError:
                raise commands.BadArgument("{} is already a self-assignable role.".format(role.name))

        elif setting == "remove":
            try:
                with db_session:
                    query = SelfAssignRoles.get(role_id=role.id)
                if query:
                    with db_session:
                        query.delete()
                    return await ctx.send('"{}" has been removed from the self-assignable roles.'.format(str(role)))
                else:
                    return await ctx.send("That role was not in the list.")
            except AttributeError:
                raise commands.BadArgument("Could not find that role.")
        else:
            return await ctx.send("No valid option given.")
github Rapptz / RoboDanny / cogs / utils / time.py View on Github external
def __init__(self, argument, *, now=None):
        super().__init__(argument, now=now)

        if self._past:
            raise commands.BadArgument('this time is in the past')
github FRCDiscord / Dozer / dozer / cogs / _roles.py View on Github external
async def give(self, ctx, member: discord.Member, *, role: discord.Role):
        """Gives a member a role. Not restricted to giveable roles."""
        if role > ctx.author.top_role:
            raise BadArgument('Cannot give roles higher than your top role!')
        await member.add_roles(role)
        e = discord.Embed(color=blurple)
        e.add_field(name='Success!', value='I Gave {} to {}!'.format(role, member))
        e.set_footer(text='Triggered by ' + ctx.author.display_name)
        await ctx.send(embed=e)
github engineer-man / felix / python / cogs / graph.py View on Github external
async def users(
        self,
        ctx,
        members: commands.Greedy[Member],
        days: int
    ):
        """Print graph of specific users measured over
        the last [days] days (max 10 users)
        """
        if not members:
            raise commands.BadArgument('Please specify at least 1 member')
        await ctx.trigger_typing()
        days = clamp(days, 1, 30)
        if await self.create_graph_messages(days, 0, members[:10]):
            with open('last_graph.png', 'rb') as g:
                file_to_send = File(g)
            await ctx.send(file=file_to_send)
        else:
            await ctx.send('Nothing found')
github Roxxers / roxbot / roxbot / cogs / util.py View on Github external
# Get information of the emoji ":Kappa:"
            ;emote :Kappa:
        """
        try:  # If emote given is custom emote
            emote = await roxbot.converters.Emoji().convert(ctx, emote)
            em = discord.Embed(title=emote.name, colour=roxbot.EmbedColours.blue)
            em.add_field(name="ID", value=str(emote.id), inline=False)
            if isinstance(emote, discord.Emoji):
                em.add_field(name="Guild", value=str(emote.guild), inline=False)
                em.add_field(name="Created At", value=roxbot.datetime.format(emote.created_at), inline=False)
            em.set_image(url=emote.url)
            return await ctx.send(embed=em)
        except commands.errors.BadArgument:  # unicode emoji
            title = emoji.demojize(emote)
            if not emoji.EMOJI_UNICODE.get(title):
                raise commands.BadArgument("Could not convert input to either unicode emoji or Discord custom emote.")

            emojis = []
            for char in emote:
                emojis.append(hex(ord(char))[2:])

            if len(emojis) > 1:
                svg_url = "https://twemoji.maxcdn.com/2/svg/{0}-{1}.svg".format(*emojis)
                png_url = "https://twemoji.maxcdn.com/2/72x72/{0}-{1}.png".format(*emojis)
            else:
                svg_url = "https://twemoji.maxcdn.com/2/svg/{0}.svg".format(*emojis)
                png_url = "https://twemoji.maxcdn.com/2/72x72/{0}.png".format(*emojis)

            em = discord.Embed(title=title, colour=roxbot.EmbedColours.blue)
            em.description = "[SVG Link]({0})\n[PNG Link]({1})".format(svg_url, png_url)
            em.set_image(url=png_url)
github Rapptz / RoboDanny / cogs / profile.py View on Github external
async def convert(self, ctx, argument):
        cog = ctx.bot.get_cog('Splatoon')
        if cog is None:
            raise commands.BadArgument('Splatoon related commands seemingly disabled.')

        query = argument.strip('"')
        if len(query) < 4:
            raise commands.BadArgument('Weapon name to query must be over 4 characters long.')

        weapons = cog.get_weapons_named(query)

        try:
            weapon = await ctx.disambiguate(weapons, lambda w: w['name'])
        except ValueError as e:
            raise commands.BadArgument(str(e)) from None
        else:
            return weapon
github fourjr / statsy / cogs / overwatch.py View on Github external
async def convert(self, ctx, argument):
        # Try to convert it to a member.
        try:
            user = await super().convert(ctx, argument)
        except commands.BadArgument:
            pass
        else:
            return user

        # Not a user so its a tag.
        return argument.replace("#", "-")
github fourjr / statsy / cogs / brawlstars.py View on Github external
async def convert(self, ctx, argument):
        # Try to convert it to a member.
        try:
            user = await super().convert(ctx, argument)
        except commands.BadArgument:
            pass
        else:
            return user

        # Not a user so its a tag.
        tag = self.resolve_tag(argument)

        if not tag:
            raise utils.InvalidBSTag
        else:
            return tag
github AlexFlipnote / discord_bot.py / cogs / mod.py View on Github external
async def convert(self, ctx, argument):
        ret = argument

        if len(ret) > 512:
            reason_max = 512 - len(ret) - len(argument)
            raise commands.BadArgument(f'reason is too long ({len(argument)}/{reason_max})')
        return ret