当前位置: 首页>>代码示例>>Python>>正文


Python commands.Bot方法代码示例

本文整理汇总了Python中discord.ext.commands.Bot方法的典型用法代码示例。如果您正苦于以下问题:Python commands.Bot方法的具体用法?Python commands.Bot怎么用?Python commands.Bot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在discord.ext.commands的用法示例。


在下文中一共展示了commands.Bot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: help_cleanup

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
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 
开发者ID:python-discord,项目名称:bot,代码行数:22,代码来源:help.py

示例2: help_embed

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
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 
开发者ID:kenng69,项目名称:modmailbotkenng,代码行数:26,代码来源:bot.py

示例3: format_bot_help

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
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 
开发者ID:cree-py,项目名称:RemixBot,代码行数:21,代码来源:bot.py

示例4: _bot

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
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) 
开发者ID:cree-py,项目名称:RemixBot,代码行数:23,代码来源:bot.py

示例5: resolve_extensions

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
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 
开发者ID:Gorialis,项目名称:jishaku,代码行数:19,代码来源:modules.py

示例6: jsk_cancel

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
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 
开发者ID:Gorialis,项目名称:jishaku,代码行数:26,代码来源:cog_base.py

示例7: __init__

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
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() 
开发者ID:python-discord,项目名称:seasonalbot,代码行数:25,代码来源:battleship.py

示例8: __init__

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
def __init__(self, bot: Bot):
        self.bot = bot

        self.matches = [
            (re.compile(i[0], re.IGNORECASE), i[1]) for i in self.match_strings
        ] 
开发者ID:CyberDiscovery,项目名称:cyberdisc-bot,代码行数:8,代码来源:cyber.py

示例9: __init__

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
def __init__(self, bot: Bot):
        self.bot = bot 
开发者ID:CyberDiscovery,项目名称:cyberdisc-bot,代码行数:4,代码来源:general.py

示例10: __init__

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
def __init__(self, bot: Bot):
        self.bot = bot
        self.update_challenge.start() 
开发者ID:CyberDiscovery,项目名称:cyberdisc-bot,代码行数:5,代码来源:maths.py

示例11: __init__

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
def __init__(self, bot: commands.Bot, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.client = bot
        self.log_channel = self.client.get_channel(LOGGING_CHANNEL_ID) 
开发者ID:CyberDiscovery,项目名称:cyberdisc-bot,代码行数:7,代码来源:log.py

示例12: __init__

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
def __init__(self, bot: Bot) -> None:
        self.bot = bot
        self.old_help_command = bot.help_command
        bot.help_command = CustomHelpCommand()
        bot.help_command.cog = self 
开发者ID:python-discord,项目名称:bot,代码行数:7,代码来源:help.py

示例13: setup

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
def setup(bot: Bot) -> None:
    """Load the Help cog."""
    bot.add_cog(Help(bot))
    log.info("Cog loaded: Help") 
开发者ID:python-discord,项目名称:bot,代码行数:6,代码来源:help.py

示例14: setup

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
def setup(bot: Bot) -> None:
    Card.convert = CardConverter.convert
    modules = glob.glob(path.join(path.dirname(__file__), '*.py'))
    files = [path.basename(f)[:-3] for f in modules if path.isfile(f) and not f.endswith('__init__.py')]

    commands, names = [], []
    for mod in files:
        n = 0
        m = importlib.import_module(f'.{mod}', package=__name__)
        for _, obj in inspect.getmembers(m):
            if isinstance(obj, Command):
                names.append(obj.name)
                names += obj.aliases
                commands.append(obj)
                n += 1
        if n == 0:
            print(f'No command found in {m.__name__}')

    aliases = text.unambiguous_prefixes(names)
    for cmd in commands:
        to_add = []
        for prefix in aliases:
            if cmd.name.startswith(prefix):
                to_add.append(prefix)
            for alias in cmd.aliases:
                if alias.startswith(prefix):
                    to_add.append(prefix)
        cmd.aliases += to_add
        bot.add_command(cmd) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:31,代码来源:__init__.py

示例15: close

# 需要导入模块: from discord.ext import commands [as 别名]
# 或者: from discord.ext.commands import Bot [as 别名]
def close(self) -> None:
        try:
            p = await asyncio.create_subprocess_shell('git pull')
            await p.wait()
            p = await asyncio.create_subprocess_shell(f'{sys.executable} -m pip install -U -r requirements.txt --no-cache')
            await p.wait()
        except Exception as c: # pylint: disable=broad-except
            repo.create_issue('Bot error while closing', 'discord user', 'discordbot', 'PennyDreadfulMTG/perf-reports', exception=c)
        await super().close() 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:11,代码来源:bot.py


注:本文中的discord.ext.commands.Bot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。