當前位置: 首頁>>代碼示例>>Python>>正文


Python Client.get_server方法代碼示例

本文整理匯總了Python中discord.Client.get_server方法的典型用法代碼示例。如果您正苦於以下問題:Python Client.get_server方法的具體用法?Python Client.get_server怎麽用?Python Client.get_server使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在discord.Client的用法示例。


在下文中一共展示了Client.get_server方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: update_vanity_dictionary

# 需要導入模塊: from discord import Client [as 別名]
# 或者: from discord.Client import get_server [as 別名]
async def update_vanity_dictionary(client: discord.Client, config: dict):
    """This function uses the config to create a dictionary for the role command, which makes it possible to change roles to a predetermined list of roles."""

    # We wait until the client is logged in
    await client.wait_until_ready()

    # The lookup dictionary for vanity commands
    vanity_dict = {}

    # We fill the dict with the commands that are enabled
    for server_id in config["vanity_role_commands"]["server_ids_and_roles"]:
        # This is the dict for the current server, which we will fill with command/role name, to role id mappings
        vanity_dict[server_id] = {}

        # We get the server object and a list of the role ids the server has
        server = client.get_server(server_id)

        if server is not None:
            server_role_ids = [x.id for x in server.roles]

            # We loop through all the commands
            for role_name in config["vanity_role_commands"]["server_ids_and_roles"][server_id]:
                # We check if the role id exists on the specified server
                if str(config["vanity_role_commands"]["server_ids_and_roles"][server_id][role_name]) in server_role_ids:
                    # It exists, so we add it to the dictionary
                    vanity_dict[server_id][role_name.lower().strip()] = \
                        config["vanity_role_commands"]["server_ids_and_roles"][server_id][role_name]

                else:
                    # The role does not exist, so we tell the user to fix their config
                    helpers.log_warning(
                        "Vanity command \"{0:s}\", could not be created as role with id {1:d} does not exist on server {2:s}.".format(
                            role_name, config["vanity_role_commands"]["server_ids_and_roles"][server_id][role_name],
                            server.name))

    global vanity_commands
    vanity_commands = vanity_dict
開發者ID:Drummersbrother,項目名稱:anna-bot,代碼行數:39,代碼來源:vanity_role_commands.py


注:本文中的discord.Client.get_server方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。