Python discord.ext.commands.Bot() Examples

The following are 30 code examples of discord.ext.commands.Bot(). 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: modules.py    From jishaku with MIT License 6 votes vote down vote up
def resolve_extensions(bot: commands.Bot, name: str) -> list:
    """
    Tries to resolve extension queries into a list of extension names.
    """

    exts = []
    for ext in braceexpand(name):
        if ext.endswith('.*'):
            module_parts = ext[:-2].split('.')
            path = pathlib.Path(*module_parts)
            exts.extend(find_extensions_in(path))
        elif ext == '~':
            exts.extend(bot.extensions)
        else:
            exts.append(ext)

    return exts 
Example #2
Source File: bot.py    From modmailbotkenng with MIT License 6 votes vote down vote up
def help_embed(self, prefix):
        em = discord.Embed(color=0x00FFFF)
        em.set_author(name='Mod Mail - Help', icon_url=self.user.avatar_url)
        em.description = 'This bot is a python implementation of a stateless "Mod Mail" bot. ' \
                         'Made by kenng and improved by the suggestions of others. This bot ' \
                         'saves no data and utilises channel topics for storage and syncing.' 
                 

        cmds = f'`{prefix}setup [modrole] <- (optional)` - Command that sets up the bot.\n' \
               f'`{prefix}reply <message...>` - Sends a message to the current thread\'s recipient.\n' \
               f'`{prefix}close` - Closes the current thread and deletes the channel.\n' \
               f'`{prefix}disable` - Closes all threads and disables modmail for the server.\n' \
               f'`{prefix}customstatus` - Sets the Bot status to whatever you want.' \
               f'`{prefix}block` - Blocks a user from using modmail!' \
               f'`{prefix}unblock` - Unblocks a user from using modmail!'

        warn = 'Do not manually delete the category or channels as it will break the system. ' \
               'Modifying the channel topic will also break the system.'
        em.add_field(name='Commands', value=cmds)
        em.add_field(name='Warning', value=warn)
        em.add_field(name='Github', value='https://github.com/kenng69/modmailbotkenng')
        em.set_footer(text='Star the repository to unlock hidden features!')

        return em 
Example #3
Source File: battleship.py    From seasonalbot with MIT License 6 votes vote down vote up
def __init__(
        self,
        bot: commands.Bot,
        channel: discord.TextChannel,
        player1: discord.Member,
        player2: discord.Member
    ) -> None:

        self.bot = bot
        self.public_channel = channel

        self.p1 = Player(player1, None, None, self.generate_grid())
        self.p2 = Player(player2, None, None, self.generate_grid())

        self.gameover: bool = False

        self.turn: typing.Optional[discord.Member] = None
        self.next: typing.Optional[discord.Member] = None

        self.match: typing.Optional[typing.Match] = None
        self.surrender: bool = False

        self.setup_grids() 
Example #4
Source File: help.py    From bot with MIT License 6 votes vote down vote up
def help_cleanup(bot: Bot, author: Member, message: Message) -> None:
    """
    Runs the cleanup for the help command.

    Adds the :trashcan: reaction that, when clicked, will delete the help message.
    After a 300 second timeout, the reaction will be removed.
    """
    def check(reaction: Reaction, user: User) -> bool:
        """Checks the reaction is :trashcan:, the author is original author and messages are the same."""
        return str(reaction) == DELETE_EMOJI and user.id == author.id and reaction.message.id == message.id

    await message.add_reaction(DELETE_EMOJI)

    try:
        await bot.wait_for("reaction_add", check=check, timeout=300)
        await message.delete()
    except TimeoutError:
        await message.remove_reaction(DELETE_EMOJI, bot.user)
    except NotFound:
        pass 
Example #5
Source File: cog_base.py    From jishaku with MIT License 6 votes vote down vote up
def jsk_cancel(self, ctx: commands.Context, *, index: int):
        """
        Cancels a task with the given index.

        If the index passed is -1, will cancel the last task instead.
        """

        if not self.tasks:
            return await ctx.send("No tasks to cancel.")

        if index == -1:
            task = self.tasks.pop()
        else:
            task = discord.utils.get(self.tasks, index=index)
            if task:
                self.tasks.remove(task)
            else:
                return await ctx.send("Unknown task.")

        task.task.cancel()
        return await ctx.send(f"Cancelled task {task.index}: `{task.ctx.command.qualified_name}`,"
                              f" invoked at {task.ctx.message.created_at.strftime('%Y-%m-%d %H:%M:%S')} UTC")

    # Bot management commands 
Example #6
Source File: bot.py    From RemixBot with MIT License 6 votes vote down vote up
def format_bot_help(ctx):
    signatures = []
    fmt = ''
    commands = []
    for cmd in bot.commands:
        if not cmd.hidden:
            if type(cmd.instance).__name__ == 'NoneType':
                commands.append(cmd)
                signatures.append(len(cmd.name) + len(ctx.prefix))
    max_length = max(signatures)
    abc = sorted(commands, key=lambda x: x.name)
    for c in abc:
        fmt += f'`{ctx.prefix + c.name:<{max_length}} '
        fmt += f'{c.short_doc:<{max_length}}`\n'
    em = discord.Embed(title='Bot', color=discord.Color.green())
    em.description = '*Commands for the main bot.*'
    em.add_field(name='Commands', value=fmt)

    return em 
Example #7
Source File: bot.py    From RemixBot with MIT License 6 votes vote down vote up
def _bot(ctx):
    '''Shows info about bot'''
    em = discord.Embed(color=discord.Color.green())
    em.title = 'Bot Info'
    em.set_author(name=ctx.author.name, icon_url=ctx.author.avatar_url)
    try:
        em.description = bot.psa + '\n[Support Server](https://discord.gg/RzsYQ9f)'
    except AttributeError:
        em.description = 'A multipurpose bot made by SharpBit, Victini, AntonyJoseph03, Free TNT and Sleedyak.\n[Support Server](https://discord.gg/RzsYQ9f)'
    em.add_field(name="Servers", value=len(bot.guilds))
    em.add_field(name="Online Users", value=str(len({m.id for m in bot.get_all_members() if m.status is not discord.Status.offline})))
    em.add_field(name='Total Users', value=len(bot.users))
    em.add_field(name='Channels', value=f"{sum(1 for g in bot.guilds for _ in g.channels)}")
    em.add_field(name="Library", value=f"discord.py")
    em.add_field(name="Bot Latency", value=f"{bot.ws.latency * 1000:.0f} ms")
    em.add_field(name="Invite", value=f"[Click Here](https://discordapp.com/oauth2/authorize?client_id={bot.user.id}&scope=bot&permissions=268905542)")
    em.add_field(name='GitHub', value='[Click here](https://github.com/cree-py/RemixBot)')
    em.add_field(name="Upvote this bot!", value=f"[Click here](https://discordbots.org/bot/{bot.user.id}) :reminder_ribbon:")

    em.set_footer(text="RemixBot | Powered by discord.py")
    await ctx.send(embed=em) 
Example #8
Source File: easter_riddle.py    From seasonalbot with MIT License 5 votes vote down vote up
def __init__(self, bot: commands.Bot):
        self.bot = bot
        self.winners = []
        self.correct = ""
        self.current_channel = None 
Example #9
Source File: movie.py    From seasonalbot with MIT License 5 votes vote down vote up
def setup(bot: Bot) -> None:
    """Load Movie Cog."""
    bot.add_cog(Movie(bot)) 
Example #10
Source File: error_handler.py    From seasonalbot with MIT License 5 votes vote down vote up
def setup(bot: commands.Bot) -> None:
    """Error handler Cog load."""
    bot.add_cog(CommandErrorHandler(bot)) 
Example #11
Source File: bookmark.py    From seasonalbot with MIT License 5 votes vote down vote up
def __init__(self, bot: commands.Bot):
        self.bot = bot 
Example #12
Source File: april_fools_vids.py    From seasonalbot with MIT License 5 votes vote down vote up
def __init__(self, bot: commands.Bot):
        self.bot = bot
        self.yt_vids = self.load_json()
        self.youtubers = ['google']  # will add more in future 
Example #13
Source File: egghead_quiz.py    From seasonalbot with MIT License 5 votes vote down vote up
def __init__(self, bot: commands.Bot) -> None:
        self.bot = bot
        self.quiz_messages = {} 
Example #14
Source File: egghead_quiz.py    From seasonalbot with MIT License 5 votes vote down vote up
def setup(bot: commands.Bot) -> None:
    """Egghead Quiz Cog load."""
    bot.add_cog(EggheadQuiz(bot)) 
Example #15
Source File: avatar_easterifier.py    From seasonalbot with MIT License 5 votes vote down vote up
def setup(bot: commands.Bot) -> None:
    """Avatar Easterifier Cog load."""
    bot.add_cog(AvatarEasterifier(bot)) 
Example #16
Source File: egg_decorating.py    From seasonalbot with MIT License 5 votes vote down vote up
def __init__(self, bot: commands.Bot) -> None:
        self.bot = bot 
Example #17
Source File: minesweeper.py    From seasonalbot with MIT License 5 votes vote down vote up
def setup(bot: commands.Bot) -> None:
    """Load the Minesweeper cog."""
    bot.add_cog(Minesweeper(bot)) 
Example #18
Source File: movie.py    From seasonalbot with MIT License 5 votes vote down vote up
def __init__(self, bot: Bot):
        self.bot = bot
        self.http_session: ClientSession = bot.http_session 
Example #19
Source File: magic_8ball.py    From seasonalbot with MIT License 5 votes vote down vote up
def setup(bot: commands.Bot) -> None:
    """Magic 8ball Cog load."""
    bot.add_cog(Magic8ball(bot)) 
Example #20
Source File: magic_8ball.py    From seasonalbot with MIT License 5 votes vote down vote up
def __init__(self, bot: commands.Bot):
        self.bot = bot
        with open(Path("bot/resources/evergreen/magic8ball.json"), "r", encoding="utf8") as file:
            self.answers = json.load(file) 
Example #21
Source File: fun.py    From seasonalbot with MIT License 5 votes vote down vote up
def setup(bot: commands.Bot) -> None:
    """Fun Cog load."""
    bot.add_cog(Fun(bot)) 
Example #22
Source File: snakes_cog.py    From seasonalbot with MIT License 5 votes vote down vote up
def __init__(self, bot: Bot):
        self.active_sal = {}
        self.bot = bot
        self.snake_names = utils.get_resource("snake_names")
        self.snake_idioms = utils.get_resource("snake_idioms")
        self.snake_quizzes = utils.get_resource("snake_quiz")
        self.snake_facts = utils.get_resource("snake_facts")

    # region: Helper methods 
Example #23
Source File: __init__.py    From seasonalbot with MIT License 5 votes vote down vote up
def setup(bot: commands.Bot) -> None:
    """Snakes Cog load."""
    bot.add_cog(Snakes(bot)) 
Example #24
Source File: uptime.py    From seasonalbot with MIT License 5 votes vote down vote up
def setup(bot: commands.Bot) -> None:
    """Uptime Cog load."""
    bot.add_cog(Uptime(bot)) 
Example #25
Source File: uptime.py    From seasonalbot with MIT License 5 votes vote down vote up
def __init__(self, bot: commands.Bot):
        self.bot = bot 
Example #26
Source File: recommend_game.py    From seasonalbot with MIT License 5 votes vote down vote up
def setup(bot: commands.Bot) -> None:
    """Loads the RecommendGame cog."""
    bot.add_cog(RecommendGame(bot)) 
Example #27
Source File: 8bitify.py    From seasonalbot with MIT License 5 votes vote down vote up
def setup(bot: commands.Bot) -> None:
    """Cog load."""
    bot.add_cog(EightBitify(bot)) 
Example #28
Source File: 8bitify.py    From seasonalbot with MIT License 5 votes vote down vote up
def __init__(self, bot: commands.Bot) -> None:
        self.bot = bot 
Example #29
Source File: trivia_quiz.py    From seasonalbot with MIT License 5 votes vote down vote up
def setup(bot: commands.Bot) -> None:
    """Load the cog."""
    bot.add_cog(TriviaQuiz(bot)) 
Example #30
Source File: trivia_quiz.py    From seasonalbot with MIT License 5 votes vote down vote up
def __init__(self, bot: commands.Bot) -> None:
        self.bot = bot
        self.questions = self.load_questions()
        self.game_status = {}  # A variable to store the game status: either running or not running.
        self.game_owners = {}  # A variable to store the person's ID who started the quiz game in a channel.
        self.question_limit = 4
        self.player_scores = {}  # A variable to store all player's scores for a bot session.
        self.game_player_scores = {}  # A variable to store temporary game player's scores.
        self.categories = {
            "general": "Test your general knowledge"
            # "retro": "Questions related to retro gaming."
        }