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


Python Client.has_plugin方法代码示例

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


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

示例1: on_command

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import has_plugin [as 别名]
def on_command(client: discord.Client, message: discord.Message, args: list):
    # Basic check
    if args[0] == "!ping":
        start = datetime.now()
        pong = yield from client.send_message(message.channel, "pong")
        end = datetime.now()
        response = (end - start).microseconds / 1000
        yield from client.edit_message(pong, "pong `{}ms`".format(response))

        logging.info("Response time: {}ms".format(response))

    # Roll from 1-100 or more
    elif args[0] == "!roll":
        if len(args) > 1:
            try:
                roll = random.randint(1, int(args[1]))
            except ValueError:
                roll = random.randint(1, 100)
        else:
            roll = random.randint(1, 100)

        yield from client.send_message(message.channel, "{0.mention} rolls {1}".format(message.author, roll))

    # Handle bot feature requests
    # (warning: this code is not representative of what I stand for in programming. I'm sorry.)
    elif args[0] == "!feature":
        m = "Please see `!help feature`."
        if len(args) > 2:
            plugin = args[1]
            if client.has_plugin(plugin):
                # Initialize the plugin for features
                if plugin not in feature_reqs.data:
                    feature_reqs.data[plugin] = []

                req_list = feature_reqs.data[plugin]

                # List feature request
                if args[2].startswith("#"):
                    feature_id = get_req_id(args[2])

                    if feature_id is not None:
                        if 0 <= feature_id < len(req_list):
                            m = "```diff\n" + format_req(plugin, feature_id) + "```"
                        else:
                            m = "There is no such feature. Try `!feature {} list`.".format(plugin)

                # List all feature requests or request with given ID.
                if args[2] == "list":
                    m = "```diff\n"
                    for req_id in range(len(req_list)):
                        m += format_req(plugin, req_id) + "\n"

                    m += "```"

                # Create a new feature
                elif args[2] == "new" or args[2] == "add" and len(args) > 3:
                    feature = " ".join(args[3:]).replace("\n", " ")

                    if feature not in req_list:
                        feature_reqs.data[plugin].append(feature)
                        feature_reqs.save()

                        m = "Feature saved as `{}` id **#{}**.".format(plugin, len(req_list))

                # Owner commands
                if client.is_owner(message.author):
                    # Mark a feature as complete
                    if args[2] == "mark" and len(args) > 3:
                        feature_id = get_req_id(args[3])

                        if feature_id is not None:
                            if 0 <= feature_id < len(req_list):
                                req = feature_reqs.data[plugin][feature_id]

                                if not req.endswith("+++"):
                                    feature_reqs.data[plugin][feature_id] += "+++"
                                    feature_reqs.save()

                                    m = "Marked feature with `{}` id **#{}**.".format(plugin, feature_id + 1)
                                else:
                                    feature_reqs.data[plugin][feature_id] = req[:-3]
                                    feature_reqs.save()

                                    m = "Unmarked feature with `{}` id **#{}**.".format(plugin, feature_id + 1)
                            else:
                                m = "There is no such feature. Try `!feature {} list`.".format(plugin)

                    # Remove a feature request
                    elif args[2] == "remove"and len(args) > 3:
                        feature_id = get_req_id(args[3])

                        if feature_id is not None:
                            if 0 <= feature_id < len(req_list):
                                feature_reqs.data[plugin].pop(feature_id)
                                feature_reqs.save()

                                m = "Removed feature with `{}` id **#{}**.".format(plugin, feature_id + 1)
                            else:
                                m = "There is no such feature. Try `!feature {} list`.".format(plugin)

#.........这里部分代码省略.........
开发者ID:EdwardBetts,项目名称:PCBOT,代码行数:103,代码来源:basic.py


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