How to use the discord.ext.commands 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 NotSoSuper / NotSoBot / mods / Wc.py View on Github external
	@commands.group(pass_context=True, name='wc', aliases=['wordcloud', 'wordc'], invoke_without_command=True)
	@commands.cooldown(10, 1)
	async def wc(self, ctx, *urls:str):
		max_messages = 500
		custom = False
		if len(urls) == 1:
			if urls[0].isdigit():
				max_messages = int(urls[0])
		elif len(urls) > 1:
			get_images = await self.get_images(ctx, urls=urls, scale=4000)
			if not get_images:
				return
			custom = True
			image, scale, scale_msg = get_images
			image = await self.bytes_download(image[0])
			if scale:
				max_messages = int(scale)
github Run1e / AceBot / cogs / guilds / autohotkey.py View on Github external
async def on_command_error(self, ctx, error):
		if not await self.__local_check(ctx) or not await self.bot.can_run(ctx):
			return

		# command not found? docs search it. only if message string is not *only* dots though
		if isinstance(error, commands.CommandNotFound) and not re.search('^\.{2}', ctx.message.content):
			await ctx.invoke(self.docs, search=ctx.message.content[1:])
github PythonistaGuild / Wavelink / examples / advanced.py View on Github external
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.context: commands.Context = kwargs.get('context', None)
        if self.context:
            self.dj: discord.Member = self.context.author

        self.queue = asyncio.Queue()
        self.controller = None

        self.waiting = False
        self.updating = False

        self.pause_votes = set()
        self.resume_votes = set()
        self.skip_votes = set()
        self.shuffle_votes = set()
        self.stop_votes = set()
github Rapptz / RoboDanny / cogs / tournament.py View on Github external
def in_booyah_guild():
    def predicate(ctx):
        return ctx.guild and ctx.guild.id == BOOYAH_GUILD_ID
    return commands.check(predicate)
github nh-server / Kurisu / kurisu.py View on Github external
if isinstance(exc, commands.CommandNotFound):
            return

        elif isinstance(exc, commands.ArgumentParsingError):
            await ctx.send_help(ctx.command)

        elif isinstance(exc, commands.NoPrivateMessage):
            await ctx.send(f'`{command}` cannot be used in direct messages.')

        elif isinstance(exc, commands.MissingPermissions):
            await ctx.send(f"{author.mention} You don't have permission to use `{command}`.")

        elif isinstance(exc, commands.CheckFailure):
            await ctx.send(f'{author.mention} You cannot use `{command}`.')

        elif isinstance(exc, commands.BadArgument):
            await ctx.send(f'{author.mention} A bad argument was given: `{exc}`\n')
            await ctx.send_help(ctx.command)

        elif isinstance(exc, discord.ext.commands.errors.CommandOnCooldown):
            if not await check_staff_id(ctx, 'Helper', author.id):
                try:
                    await ctx.message.delete()
                except (discord.errors.NotFound, discord.errors.Forbidden):
                    pass
                await ctx.send(f"{author.mention} This command was used {exc.cooldown.per - exc.retry_after:.2f}s ago and is on cooldown. Try again in {exc.retry_after:.2f}s.", delete_after=10)
            else:
                await ctx.reinvoke()

        elif isinstance(exc, commands.MissingRequiredArgument):
            await ctx.send(f'{author.mention} You are missing required argument {exc.param.name}.\n')
            await ctx.send_help(ctx.command)
github FoglyOgly / Meowth / meowth / exts / dev / dev_cog.py View on Github external
async def source(self, ctx, *, command: BotCommand):
        """Displays the source code for a particular command.
        There is a per-user, 2 times per 5 seconds cooldown in order to prevent spam.
        """
        paginator = commands.Paginator(prefix='```py')
        for line in inspect.getsourcelines(command.callback)[0]:
            paginator.add_line(line.rstrip().replace('`', '\u200b`'))

        for p in paginator.pages:
            await ctx.send(p)
github corpnewt / CorpBot.py / Cogs / Setup.py View on Github external
import asyncio
import discord
from   discord.ext import commands
from   Cogs import Settings
from   Cogs import DisplayName
from   Cogs import Nullify

def setup(bot):
	# Add the bot and deps
	settings = bot.get_cog("Settings")
	bot.add_cog(Setup(bot, settings))

# This is the Uptime module. It keeps track of how long the bot's been up

class Setup(commands.Cog):

	# Init with the bot reference, and a reference to the settings var
	def __init__(self, bot, settings):
		self.bot = bot
		self.settings = settings
		global Utils, DisplayName
		Utils = self.bot.get_cog("Utils")
		DisplayName = self.bot.get_cog("DisplayName")

	def suppressed(self, guild, msg):
		# Check if we're suppressing @here and @everyone mentions
		if self.settings.getServerStat(guild, "SuppressMentions"):
			return Nullify.clean(msg)
		else:
			return msg
github nguuuquaaa / Belphegor / belphegor / sticker.py View on Github external
    @commands.Cog.listener()
    async def on_command_completion(self, ctx):
        if ctx.command.name == "reload":
            if ctx.args[2] == "misc":
                self.auto_rep_disabled = self.bot.get_cog("Misc").auto_rep_disabled
github abdurrahmanKhan / DISCORD-BOT / main.py View on Github external
@commands.has_role("Friends")                        #if you wanna specify to whom you give permission to do so.
async def kick(ctx, user: discord.Member):           #----------------------------------------------------------
    await bot.say(":boot: Seeya, {}, Ya loser!".format(user.name))
    await bot.kick(user)
github Support-Manager / Discord-Bot / bot / models.py View on Github external
async def convert(self, ctx, argument):
        if type(argument) == str:
            if argument.startswith('#'):
                argument = argument[1:]
            else:
                try:
                    channel = await commands.TextChannelConverter().convert(ctx, argument)
                except commands.BadArgument:
                    channel = None

                if channel is not None:
                    argument = channel.name  # channel name == ticket id

        try:
            t = self.get(int(argument), ctx.db_guild, ctx=ctx)
        except ValueError:
            t = None

        if t is None:
            raise commands.BadArgument("Given ticket can't be found.")
        else:
            return t