本文整理汇总了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