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


Python Client.say方法代码示例

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


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

示例1: game

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def game(client: discord.Client, message: discord.Message, name: Annotate.Content=None):
    """ Stop playing or set game to `name`. """
    yield from client.change_status(discord.Game(name=name, type=0))

    if name:
        yield from client.say(message, "*Set the game to* **{}**.".format(name))
    else:
        yield from client.say(message, "*No longer playing.*")
开发者ID:xZwop,项目名称:PCBOT,代码行数:10,代码来源:builtin.py

示例2: disable

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def disable(client: discord.Client, message: discord.Message, trigger: str.lower):
    """ Disable a command. """
    # If the specified trigger is not in the blacklist, we add it
    if trigger not in lambda_config.data["blacklist"]:
        lambda_config.data["blacklist"].append(trigger)
        lambda_config.save()
        yield from client.say(message, "Command `{}` disabled.".format(trigger))
    else:
        assert trigger in lambdas.data, "Command `{}` does not exist.".format(trigger)

        # The command exists so surely it must be disabled
        yield from client.say(message, "Command `{}` is already disabled.".format(trigger))
开发者ID:xZwop,项目名称:PCBOT,代码行数:14,代码来源:builtin.py

示例3: import_

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def import_(client: discord.Client, message: discord.Message, module: str, attr: str=None):
    """ Import the specified module. Specifying `attr` will act like `from attr import module`. """
    try:
        import_module(module, attr)
    except ImportError:
        yield from client.say(message, "Unable to import `{}`.".format(module))
    except KeyError:
        yield from client.say(message, "Unable to import `{}` from `{}`.".format(attr, module))
    else:
        # There were no errors when importing, so we add the name to our startup imports
        lambda_config.data["imports"].append((module, attr))
        lambda_config.save()
        yield from client.say(message, "Imported and setup `{}` for import.".format(attr or module))
开发者ID:xZwop,项目名称:PCBOT,代码行数:15,代码来源:builtin.py

示例4: pp_

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def pp_(client: discord.Client, message: discord.Message, beatmap_url: str.lower, *options):
    """ Calculate and return the would be pp using `oppai`.

    Options are a parsed set of command-line arguments:  /
    `([acc]% | [num_100s]x100 [num_50s]x50) +[mods] [combo]x [misses]m scorev[scoring_version]`"""
    global last_calc_beatmap

    # This service is only supported on Linux as of yet
    assert platform.system() == "Linux", "This service is unsupported since the bot is not hosted using Linux."

    # Make sure the bot has access to "oppai" lib
    assert os.path.exists(os.path.join(oppai_path, "oppai")), \
        "This service is unavailable until the owner sets up the `oppai` lib."

    # Only download and request when the id is different from the last check
    if last_calc_beatmap["beatmap_id"] not in beatmap_url and last_calc_beatmap["beatmapset_id"] not in beatmap_url:
        # Parse beatmap URL and download the beatmap .osu
        try:
            beatmap = yield from api.beatmap_from_url(beatmap_url)
        except Exception as e:
            yield from client.say(message, e)
            return

        # Download and save the beatmap pp_map.osu
        beatmap_file, _ = yield from utils.download_file(host + "osu/" + str(beatmap["beatmap_id"]))
        with open(os.path.join(oppai_path, "pp_map.osu"), "wb") as f:
            f.write(beatmap_file)
    else:
        beatmap = last_calc_beatmap

    last_calc_beatmap = beatmap

    command_args = [os.path.join(oppai_path, "oppai"), os.path.join(oppai_path, "pp_map.osu")]

    # Add additional options
    if options:
        command_args.extend(options)

    command_stream = Popen(command_args, universal_newlines=True, stdout=PIPE)
    output = command_stream.stdout.read()
    match = re.search(r"(?P<pp>[0-9.e+]+)pp", output)

    # Something went wrong with our service
    assert match, "A problem occurred when parsing the beatmap."

    # We're done! Tell the user how much this score is worth.
    yield from client.say(message, "*{artist} - {title}* **[{version}] {1}** would be worth `{0:,}pp`.".format(
        float(match.group("pp")), " ".join(options), **beatmap))
开发者ID:xZwop,项目名称:PCBOT,代码行数:50,代码来源:osu.py

示例5: define

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def define(client: discord.Client, message: discord.Message, term: Annotate.LowerCleanContent):
    """ Defines a term using Urban Dictionary. """

    json = yield from utils.download_json("http://api.urbandictionary.com/v0/define", term=term)
    definitions = json["list"] if "list" in json else []

    # Make sure we have something to define
    assert definitions, "Could not define `{}`.".format(term)

    # Send any valid definition (length of message < 2000 characters)
    msg = ""
    for definition in definitions:
        # Format example in code if there is one
        if "example" in definition and definition["example"]:
            definition["example"] = "```{}```".format(definition["example"])

        # Format definition
        msg = "**{}**:\n{}\n{}".format(
            definition["word"],
            definition["definition"],
            definition["example"]
        )

        # If this definition fits in a message, break the loop so that we can send it
        if len(msg) <= 2000:
            break

    # Cancel if the message is too long
    assert len(msg) <= 2000, "Defining this word would be a bad idea."

    # Send the definition
    yield from client.say(message, msg)
开发者ID:xZwop,项目名称:PCBOT,代码行数:34,代码来源:web.py

示例6: filter_type

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def filter_type(client: discord.Client, message: discord.Message, slot_1: str.lower, slot_2: str.lower=None):
    matched_pokemon = []
    assert_type(slot_1)

    # Find all pokemon with the matched criteria
    if slot_2:
        assert_type(slot_2)

        # If two slots are provided, search for pokemon with both types matching
        for pokemon in pokedex.values():
            if pokemon["types"] == [slot_1, slot_2]:
                matched_pokemon.append(pokemon["locale_name"])
    else:
        # All pokemon have a type in their first slot, so check if these are equal
        for pokemon in pokedex.values():
            if pokemon["types"][0] == slot_1:
                matched_pokemon.append(pokemon["locale_name"])

    types = [slot_1] if slot_2 is None else [slot_1, slot_2]

    # There might not be any pokemon with the specified types
    assert matched_pokemon, "Looks like there are no pokemon of type **{}**!".format(format_type(types))

    yield from client.say(message, "**Pokemon with type {}**: ```\n{}```".format(
        format_type(types), ", ".join(sorted(matched_pokemon))))
开发者ID:xZwop,项目名称:PCBOT,代码行数:27,代码来源:pokedex.py

示例7: debug

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def debug(client: discord.Client, message: discord.Message):
    """ Display some debug info. """
    yield from client.say(message, "Sent `{}` requests since the bot started (`{}`).\n"
                                   "Members registered for update: {}".format(
        api.requests_sent,
        client.time_started.ctime(),
        utils.format_members(*[d["member"] for d in osu_tracking.values()])
    ))
开发者ID:xZwop,项目名称:PCBOT,代码行数:10,代码来源:osu.py

示例8: url

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def url(client: discord.Client, message: discord.Message, member: Annotate.Member=Annotate.Self):
    """ Display the member's osu! profile URL. """
    # Member might not be registered
    assert member.id in osu_config.data["profiles"], "No osu! profile assigned to **{}**!".format(member.name)

    # Send the URL since the member is registered
    yield from client.say(message, "**{0.display_name}'s profile:** <https://osu.ppy.sh/u/{1}>".format(
        member, osu_config.data["profiles"][member.id]))
开发者ID:xZwop,项目名称:PCBOT,代码行数:10,代码来源:osu.py

示例9: unload

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def unload(client: discord.Client, message: discord.Message, name: str.lower):
    """ Unloads a plugin. """
    assert plugins.get_plugin(name), "`{}` is not a loaded plugin.".format(name)

    # The plugin is loaded so we unload it
    yield from plugins.save_plugin(name)
    plugins.unload_plugin(name)
    yield from client.say(message, "Plugin `{}` unloaded.".format(name))
开发者ID:xZwop,项目名称:PCBOT,代码行数:10,代码来源:builtin.py

示例10: lambda_

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def lambda_(client: discord.Client, message: discord.Message):
    """ Create commands. See `{pre}help do` for information on how the code works.

        **In addition**, there's the `arg(i, default=0)` function for getting arguments in positions,
        where the default argument is what to return when the argument does not exist.
        **Owner command unless no argument is specified.**"""
    yield from client.say(message,
                          "**Lambdas:** ```\n" "{}```".format(", ".join(sorted(lambdas.data.keys()))))
开发者ID:xZwop,项目名称:PCBOT,代码行数:10,代码来源:builtin.py

示例11: remove

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def remove(client: discord.Client, message: discord.Message, trigger: str.lower):
    """ Remove a command. """
    assert trigger in lambdas.data, "Command `{}` does not exist.".format(trigger)

    # The command specified exists and we remove it
    del lambdas.data[trigger]
    lambdas.save()
    yield from client.say(message, "Command `{}` removed.".format(trigger))
开发者ID:xZwop,项目名称:PCBOT,代码行数:10,代码来源:builtin.py

示例12: reload

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def reload(client: discord.Client, message: discord.Message, name: str.lower=None):
    """ Reloads all plugins or the specified plugin. """
    if name:
        assert plugins.get_plugin(name), "`{}` is not a plugin".format(name)

        # The plugin entered is valid so we reload it
        yield from plugins.save_plugin(name)
        plugins.reload_plugin(name)
        yield from client.say(message, "Reloaded plugin `{}`.".format(name))
    else:
        # Reload all plugins
        yield from plugins.save_plugins()

        for plugin_name in plugins.all_keys():
            plugins.reload_plugin(plugin_name)

        yield from client.say(message, "All plugins reloaded.")
开发者ID:xZwop,项目名称:PCBOT,代码行数:19,代码来源:builtin.py

示例13: load

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def load(client: discord.Client, message: discord.Message, name: str.lower):
    """ Loads a plugin. """
    assert not plugins.get_plugin(name), "Plugin `{}` is already loaded.".format(name)

    # The plugin isn't loaded so we'll try to load it
    assert plugins.load_plugin(name), "Plugin `{}` could not be loaded.".format(name)

    # The plugin was loaded successfully
    yield from client.say(message, "Plugin `{}` loaded.".format(name))
开发者ID:xZwop,项目名称:PCBOT,代码行数:11,代码来源:builtin.py

示例14: resize

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def resize(client: discord.Client, message: discord.Message,
           url: str, resolution: parse_resolution, *options, extension: str=None):
    """ Resize an image with the given resolution formatted as `<width>x<height>`
    with an optional extension. """
    # Make sure the URL is valid
    try:
        image_bytes, headers = yield from utils.download_file(url)
    except ValueError:
        yield from client.say(message, "The given URL is invalid.")
        return

    match = extension_regex.search(headers["CONTENT-TYPE"])
    assert match, "The given url is not an image."

    # Create some metadata
    image_format = extension or match.group("ext")

    # Set the image upload extension
    extension = image_format.lower()
    if extension.lower() == "jpeg":
        extension = "jpg"
    if image_format.lower() == "jpg":
        image_format = "JPEG"

    filename = "{}.{}".format(message.author.display_name, extension)

    # Open the image in Pillow
    image = Image.open(BytesIO(image_bytes))
    image = image.resize(resolution, Image.NEAREST if "-nearest" in options else Image.ANTIALIAS)

    # Upload the image
    buffer = BytesIO()
    try:
        image.save(buffer, image_format)
    except KeyError as e:
        yield from client.say(message, "Image format `{}` is unsupported.".format(e))
        return
    except Exception as e:
        yield from client.say(message, str(e) + ".")
        return
    buffer.seek(0)

    yield from client.send_file(message.channel, buffer, filename=filename)
开发者ID:xZwop,项目名称:PCBOT,代码行数:45,代码来源:image.py

示例15: eval_

# 需要导入模块: from discord import Client [as 别名]
# 或者: from discord.Client import say [as 别名]
def eval_(client: discord.Client, message: discord.Message, python_code: Annotate.Code):
    """ Evaluate a python expression. Can be any python code on one line that returns something. """
    code_globals.update(dict(message=message, client=client))

    try:
        result = eval(python_code, code_globals)
    except Exception as e:
        result = utils.format_exception(e)

    yield from client.say(message, "**Result:** \n```{}\n```".format(result))
开发者ID:xZwop,项目名称:PCBOT,代码行数:12,代码来源:builtin.py


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