diff options
| author | Rapptz <[email protected]> | 2016-10-17 18:25:23 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-01-03 09:51:54 -0500 |
| commit | d1d54a468a88323a8ef7798ff084a1371d5893ec (patch) | |
| tree | 21dd315df95acd2c8d6cf63cc51fa4cadc0c7155 /discord/client.py | |
| parent | Stateful Message and remove Invite.xkcd since it is removed. (diff) | |
| download | discord.py-d1d54a468a88323a8ef7798ff084a1371d5893ec.tar.xz discord.py-d1d54a468a88323a8ef7798ff084a1371d5893ec.zip | |
Rename Server to Guild everywhere.
Diffstat (limited to 'discord/client.py')
| -rw-r--r-- | discord/client.py | 444 |
1 files changed, 222 insertions, 222 deletions
diff --git a/discord/client.py b/discord/client.py index 94aaa6c4..8b69e111 100644 --- a/discord/client.py +++ b/discord/client.py @@ -28,7 +28,7 @@ from . import __version__ as library_version from .user import User from .member import Member from .channel import * -from .server import Server +from .guild import Guild from .message import Message from .invite import Invite from .object import Object @@ -37,7 +37,7 @@ from .errors import * from .state import ConnectionState from .permissions import Permissions, PermissionOverwrite from . import utils, compat -from .enums import ChannelType, ServerRegion, VerificationLevel, Status +from .enums import ChannelType, GuildRegion, VerificationLevel, Status from .voice_client import VoiceClient from .iterators import LogsFromIterator from .gateway import * @@ -118,13 +118,13 @@ class Client: Represents a list of voice connections. To connect to voice use :meth:`join_voice_channel`. To query the voice connection state use :meth:`is_voice_connected`. - servers : iterable of :class:`Server` - The servers that the connected client is a member of. + guilds : iterable of :class:`Guild` + The guilds that the connected client is a member of. private_channels : iterable of :class:`PrivateChannel` The private channels that the connected client is participating on. messages A deque_ of :class:`Message` that the client has received from all - servers and private messages. The number of messages stored in this + guilds and private messages. The number of messages stored in this deque is controlled by the ``max_messages`` parameter. email The email used to login. This is only set if login is successful, @@ -262,10 +262,10 @@ class Client: @asyncio.coroutine def _resolve_destination(self, destination): if isinstance(destination, TextChannel): - return destination.id, destination.server.id + return destination.id, destination.guild.id elif isinstance(destination, DMChannel): return destination.id, None - elif isinstance(destination, Server): + elif isinstance(destination, Guild): return destination.id, destination.id elif isinstance(destination, User): found = self.connection._get_private_channel_by_user(destination.id) @@ -287,14 +287,14 @@ class Client: raise InvalidArgument(fmt.format(destination)) def __getattr__(self, name): - if name in ('user', 'servers', 'private_channels', 'messages', 'voice_clients'): + if name in ('user', 'guilds', 'private_channels', 'messages', 'voice_clients'): return getattr(self.connection, name) else: msg = "'{}' object has no attribute '{}'" raise AttributeError(msg.format(self.__class__, name)) def __setattr__(self, name, value): - if name in ('user', 'servers', 'private_channels', 'messages', 'voice_clients'): + if name in ('user', 'guilds', 'private_channels', 'messages', 'voice_clients'): return setattr(self.connection, name, value) else: object.__setattr__(self, name, value) @@ -469,7 +469,7 @@ class Client: # if an error happens during disconnects, disregard it. pass - self.connection._remove_voice_client(voice.server.id) + self.connection._remove_voice_client(voice.guild.id) if self.ws is not None and self.ws.open: yield from self.ws.close() @@ -549,14 +549,14 @@ class Client: """Returns a :class:`Channel` or :class:`PrivateChannel` with the following ID. If not found, returns None.""" return self.connection.get_channel(id) - def get_server(self, id): - """Returns a :class:`Server` with the given ID. If not found, returns None.""" - return self.connection._get_server(id) + def get_guild(self, id): + """Returns a :class:`Guild` with the given ID. If not found, returns None.""" + return self.connection._get_guild(id) def get_all_emojis(self): """Returns a generator with every :class:`Emoji` the client can see.""" - for server in self.servers: - for emoji in server.emojis: + for guild in self.guilds: + for emoji in guild.emojis: yield emoji def get_all_channels(self): @@ -564,8 +564,8 @@ class Client: This is equivalent to: :: - for server in client.servers: - for channel in server.channels: + for guild in client.guilds: + for channel in guild.channels: yield channel Note @@ -575,8 +575,8 @@ class Client: be used for that. """ - for server in self.servers: - for channel in server.channels: + for guild in self.guilds: + for channel in guild.channels: yield channel def get_all_members(self): @@ -584,13 +584,13 @@ class Client: This is equivalent to: :: - for server in client.servers: - for member in server.members: + for guild in client.guilds: + for member in guild.members: yield member """ - for server in self.servers: - for member in server.members: + for guild in self.guilds: + for member in guild.members: yield member # listeners/waiters @@ -1068,11 +1068,11 @@ class Client: Sends a message to the destination given with the content given. - The destination could be a :class:`Channel`, :class:`PrivateChannel` or :class:`Server`. + The destination could be a :class:`Channel`, :class:`PrivateChannel` or :class:`Guild`. For convenience it could also be a :class:`User`. If it's a :class:`User` or :class:`PrivateChannel` then it sends the message via private message, otherwise it sends the message to the channel. - If the destination is a :class:`Server` then it's equivalent to calling - :attr:`Server.default_channel` and sending it there. + If the destination is a :class:`Guild` then it's equivalent to calling + :attr:`Guild.default_channel` and sending it there. If it is a :class:`Object` instance then it is assumed to be the destination ID. The destination ID is a *channel* so passing in a user @@ -1256,7 +1256,7 @@ class Client: Deleting the message failed. """ channel = message.channel - guild_id = channel.server.id if not getattr(channel, 'is_private', True) else None + guild_id = channel.guild.id if not getattr(channel, 'is_private', True) else None yield from self.http.delete_message(channel.id, message.id, guild_id) @asyncio.coroutine @@ -1295,7 +1295,7 @@ class Client: channel = messages[0].channel message_ids = [m.id for m in messages] - guild_id = channel.server.id if not getattr(channel, 'is_private', True) else None + guild_id = channel.guild.id if not getattr(channel, 'is_private', True) else None yield from self.http.delete_messages(channel.id, message_ids, guild_id) @asyncio.coroutine @@ -1434,7 +1434,7 @@ class Client: channel = message.channel content = str(new_content) if new_content else None embed = embed.to_dict() if embed else None - guild_id = channel.server.id if not getattr(channel, 'is_private', True) else None + guild_id = channel.guild.id if not getattr(channel, 'is_private', True) else None data = yield from self.http.edit_message(message.id, channel.id, content, guild_id=guild_id, embed=embed) return Message(channel=channel, state=self.connection.ctx, data=data) @@ -1640,30 +1640,30 @@ class Client: # Member management @asyncio.coroutine - def request_offline_members(self, server): + def request_offline_members(self, guild): """|coro| - Requests previously offline members from the server to be filled up - into the :attr:`Server.members` cache. This function is usually not + Requests previously offline members from the guild to be filled up + into the :attr:`Guild.members` cache. This function is usually not called. When the client logs on and connects to the websocket, Discord does not provide the library with offline members if the number of members - in the server is larger than 250. You can check if a server is large - if :attr:`Server.large` is ``True``. + in the guild is larger than 250. You can check if a guild is large + if :attr:`Guild.large` is ``True``. Parameters ----------- - server : :class:`Server` or iterable - The server to request offline members for. If this parameter is a - iterable then it is interpreted as an iterator of servers to + guild : :class:`Guild` or iterable + The guild to request offline members for. If this parameter is a + iterable then it is interpreted as an iterator of guilds to request offline members for. """ - if hasattr(server, 'id'): - guild_id = server.id + if hasattr(guild, 'id'): + guild_id = guild.id else: - guild_id = [s.id for s in server] + guild_id = [s.id for s in guild] payload = { 'op': 8, @@ -1680,18 +1680,18 @@ class Client: def kick(self, member): """|coro| - Kicks a :class:`Member` from the server they belong to. + Kicks a :class:`Member` from the guild they belong to. Warning -------- - This function kicks the :class:`Member` based on the server it - belongs to, which is accessed via :attr:`Member.server`. So you - must have the proper permissions in that server. + This function kicks the :class:`Member` based on the guild it + belongs to, which is accessed via :attr:`Member.guild`. So you + must have the proper permissions in that guild. Parameters ----------- member : :class:`Member` - The member to kick from their server. + The member to kick from their guild. Raises ------- @@ -1700,27 +1700,27 @@ class Client: HTTPException Kicking failed. """ - yield from self.http.kick(member.id, member.server.id) + yield from self.http.kick(member.id, member.guild.id) @asyncio.coroutine def ban(self, member, delete_message_days=1): """|coro| - Bans a :class:`Member` from the server they belong to. + Bans a :class:`Member` from the guild they belong to. Warning -------- - This function bans the :class:`Member` based on the server it - belongs to, which is accessed via :attr:`Member.server`. So you - must have the proper permissions in that server. + This function bans the :class:`Member` based on the guild it + belongs to, which is accessed via :attr:`Member.guild`. So you + must have the proper permissions in that guild. Parameters ----------- member : :class:`Member` - The member to ban from their server. + The member to ban from their guild. delete_message_days : int The number of days worth of messages to delete from the user - in the server. The minimum is 0 and the maximum is 7. + in the guild. The minimum is 0 and the maximum is 7. Raises ------- @@ -1729,18 +1729,18 @@ class Client: HTTPException Banning failed. """ - yield from self.http.ban(member.id, member.server.id, delete_message_days) + yield from self.http.ban(member.id, member.guild.id, delete_message_days) @asyncio.coroutine - def unban(self, server, user): + def unban(self, guild, user): """|coro| - Unbans a :class:`User` from the server they are banned from. + Unbans a :class:`User` from the guild they are banned from. Parameters ----------- - server : :class:`Server` - The server to unban the user from. + guild : :class:`Guild` + The guild to unban the user from. user : :class:`User` The user to unban. @@ -1751,28 +1751,28 @@ class Client: HTTPException Unbanning failed. """ - yield from self.http.unban(user.id, server.id) + yield from self.http.unban(user.id, guild.id) @asyncio.coroutine - def server_voice_state(self, member, *, mute=None, deafen=None): + def guild_voice_state(self, member, *, mute=None, deafen=None): """|coro| - Server mutes or deafens a specific :class:`Member`. + Guild mutes or deafens a specific :class:`Member`. Warning -------- This function mutes or un-deafens the :class:`Member` based on the - server it belongs to, which is accessed via :attr:`Member.server`. - So you must have the proper permissions in that server. + guild it belongs to, which is accessed via :attr:`Member.guild`. + So you must have the proper permissions in that guild. Parameters ----------- member : :class:`Member` - The member to unban from their server. + The member to unban from their guild. mute: Optional[bool] - Indicates if the member should be server muted or un-muted. + Indicates if the member should be guild muted or un-muted. deafen: Optional[bool] - Indicates if the member should be server deafened or un-deafened. + Indicates if the member should be guild deafened or un-deafened. Raises ------- @@ -1781,7 +1781,7 @@ class Client: HTTPException The operation failed. """ - yield from self.http.server_voice_state(member.id, member.server.id, mute=mute, deafen=deafen) + yield from self.http.guild_voice_state(member.id, member.guild.id, mute=mute, deafen=deafen) @asyncio.coroutine def edit_profile(self, password=None, **fields): @@ -1958,9 +1958,9 @@ class Client: nickname = nickname if nickname else '' if member == self.user: - yield from self.http.change_my_nickname(member.server.id, nickname) + yield from self.http.change_my_nickname(member.guild.id, nickname) else: - yield from self.http.change_nickname(member.server.id, member.id, nickname) + yield from self.http.change_nickname(member.guild.id, member.id, nickname) # Channel management @@ -2039,8 +2039,8 @@ class Client: if position < 0: raise InvalidArgument('Channel position cannot be less than 0.') - url = '{0}/{1.server.id}/channels'.format(self.http.GUILDS, channel) - channels = [c for c in channel.server.channels if c.type is channel.type] + url = '{0}/{1.guild.id}/channels'.format(self.http.GUILDS, channel) + channels = [c for c in channel.guild.channels if c.type is channel.type] if position >= len(channels): raise InvalidArgument('Channel position cannot be greater than {}'.format(len(channels) - 1)) @@ -2061,10 +2061,10 @@ class Client: yield from self.http.patch(url, json=payload, bucket='move_channel') @asyncio.coroutine - def create_channel(self, server, name, *overwrites, type=None): + def create_channel(self, guild, name, *overwrites, type=None): """|coro| - Creates a :class:`Channel` in the specified :class:`Server`. + Creates a :class:`Channel` in the specified :class:`Guild`. Note that you need the proper permissions to create the channel. @@ -2081,7 +2081,7 @@ class Client: .. code-block:: python - await client.create_channel(server, 'Voice', type=discord.ChannelType.voice) + await client.create_channel(guild, 'Voice', type=discord.ChannelType.voice) Creating a 'secret' text channel: @@ -2090,9 +2090,9 @@ class Client: everyone_perms = discord.PermissionOverwrite(read_messages=False) my_perms = discord.PermissionOverwrite(read_messages=True) - everyone = discord.ChannelPermissions(target=server.default_role, overwrite=everyone_perms) - mine = discord.ChannelPermissions(target=server.me, overwrite=my_perms) - await client.create_channel(server, 'secret', everyone, mine) + everyone = discord.ChannelPermissions(target=guild.default_role, overwrite=everyone_perms) + mine = discord.ChannelPermissions(target=guild.me, overwrite=my_perms) + await client.create_channel(guild, 'secret', everyone, mine) Or in a more 'compact' way: @@ -2100,12 +2100,12 @@ class Client: everyone = discord.PermissionOverwrite(read_messages=False) mine = discord.PermissionOverwrite(read_messages=True) - await client.create_channel(server, 'secret', (server.default_role, everyone), (server.me, mine)) + await client.create_channel(guild, 'secret', (guild.default_role, everyone), (guild.me, mine)) Parameters ----------- - server : :class:`Server` - The server to create the channel in. + guild : :class:`Guild` + The guild to create the channel in. name : str The channel's name. type : :class:`ChannelType` @@ -2119,7 +2119,7 @@ class Client: Forbidden You do not have the proper permissions to create the channel. NotFound - The server specified was not found. + The guild specified was not found. HTTPException Creating the channel failed. InvalidArgument @@ -2158,8 +2158,8 @@ class Client: perms.append(payload) - data = yield from self.http.create_channel(server.id, name, str(type), permission_overwrites=perms) - channel = Channel(server=server, state=self.connection.ctx, data=data) + data = yield from self.http.create_channel(guild.id, name, str(type), permission_overwrites=perms) + channel = Channel(guild=guild, state=self.connection.ctx, data=data) return channel @asyncio.coroutine @@ -2169,7 +2169,7 @@ class Client: Deletes a :class:`Channel`. In order to delete the channel, the client must have the proper permissions - in the server the channel belongs to. + in the guild the channel belongs to. Parameters ------------ @@ -2187,66 +2187,66 @@ class Client: """ yield from self.http.delete_channel(channel.id) - # Server management + # Guild management @asyncio.coroutine - def leave_server(self, server): + def leave_guild(self, guild): """|coro| - Leaves a :class:`Server`. + Leaves a :class:`Guild`. Note -------- - You cannot leave the server that you own, you must delete it instead - via :meth:`delete_server`. + You cannot leave the guild that you own, you must delete it instead + via :meth:`delete_guild`. Parameters ---------- - server : :class:`Server` - The server to leave. + guild : :class:`Guild` + The guild to leave. Raises -------- HTTPException - If leaving the server failed. + If leaving the guild failed. """ - yield from self.http.leave_server(server.id) + yield from self.http.leave_guild(guild.id) @asyncio.coroutine - def delete_server(self, server): + def delete_guild(self, guild): """|coro| - Deletes a :class:`Server`. You must be the server owner to delete the - server. + Deletes a :class:`Guild`. You must be the guild owner to delete the + guild. Parameters ---------- - server : :class:`Server` - The server to delete. + guild : :class:`Guild` + The guild to delete. Raises -------- HTTPException - If deleting the server failed. + If deleting the guild failed. Forbidden - You do not have permissions to delete the server. + You do not have permissions to delete the guild. """ - yield from self.http.delete_server(server.id) + yield from self.http.delete_guild(guild.id) @asyncio.coroutine - def create_server(self, name, region=None, icon=None): + def create_guild(self, name, region=None, icon=None): """|coro| - Creates a :class:`Server`. + Creates a :class:`Guild`. Parameters ---------- name : str - The name of the server. - region : :class:`ServerRegion` - The region for the voice communication server. - Defaults to :attr:`ServerRegion.us_west`. + The name of the guild. + region : :class:`GuildRegion` + The region for the voice communication guild. + Defaults to :attr:`GuildRegion.us_west`. icon : bytes The *bytes-like* object representing the icon. See :meth:`edit_profile` for more details on what is expected. @@ -2254,44 +2254,44 @@ class Client: Raises ------ HTTPException - Server creation failed. + Guild creation failed. InvalidArgument Invalid icon image format given. Must be PNG or JPG. Returns ------- - :class:`Server` - The server created. This is not the same server that is + :class:`Guild` + The guild created. This is not the same guild that is added to cache. """ if icon is not None: icon = utils._bytes_to_base64_data(icon) if region is None: - region = ServerRegion.us_west.name + region = GuildRegion.us_west.name else: region = region.name - data = yield from self.http.create_server(name, region, icon) - return Server(data=data, state=self.connection.ctx) + data = yield from self.http.create_guild(name, region, icon) + return Guild(data=data, state=self.connection.ctx) @asyncio.coroutine - def edit_server(self, server, **fields): + def edit_guild(self, guild, **fields): """|coro| - Edits a :class:`Server`. + Edits a :class:`Guild`. - You must have the proper permissions to edit the server. + You must have the proper permissions to edit the guild. - The :class:`Server` object is not directly modified afterwards until the + The :class:`Guild` object is not directly modified afterwards until the corresponding WebSocket event is received. Parameters ---------- - server: :class:`Server` - The server to edit. + guild: :class:`Guild` + The guild to edit. name: str - The new name of the server. + The new name of the guild. icon: bytes A *bytes-like* object representing the icon. See :meth:`edit_profile` for more details. Could be ``None`` to denote no icon. @@ -2300,36 +2300,36 @@ class Client: :meth:`edit_profile` for more details. Could be ``None`` to denote no invite splash. Only available for partnered servers with ``INVITE_SPLASH`` feature. - region: :class:`ServerRegion` - The new region for the server's voice communication. + region: :class:`GuildRegion` + The new region for the guild's voice communication. afk_channel: :class:`Channel` The new channel that is the AFK channel. Could be ``None`` for no AFK channel. afk_timeout: int The number of seconds until someone is moved to the AFK channel. owner: :class:`Member` - The new owner of the server to transfer ownership to. Note that you must - be owner of the server to do this. + The new owner of the guild to transfer ownership to. Note that you must + be owner of the guild to do this. verification_level: :class:`VerificationLevel` - The new verification level for the server. + The new verification level for the guild. Raises ------- Forbidden - You do not have permissions to edit the server. + You do not have permissions to edit the guild. NotFound - The server you are trying to edit does not exist. + The guild you are trying to edit does not exist. HTTPException - Editing the server failed. + Editing the guild failed. InvalidArgument The image format passed in to ``icon`` is invalid. It must be PNG or JPG. This is also raised if you are not the owner of the - server and request an ownership transfer. + guild and request an ownership transfer. """ try: icon_bytes = fields['icon'] except KeyError: - icon = server.icon + icon = guild.icon else: if icon_bytes is not None: icon = utils._bytes_to_base64_data(icon_bytes) @@ -2352,34 +2352,34 @@ class Client: fields['afk_channel_id'] = fields['afk_channel'].id if 'owner' in fields: - if server.owner != server.me: - raise InvalidArgument('To transfer ownership you must be the owner of the server.') + if guild.owner != guild.me: + raise InvalidArgument('To transfer ownership you must be the owner of the guild.') fields['owner_id'] = fields['owner'].id if 'region' in fields: fields['region'] = str(fields['region']) - level = fields.get('verification_level', server.verification_level) + level = fields.get('verification_level', guild.verification_level) if not isinstance(level, VerificationLevel): raise InvalidArgument('verification_level field must of type VerificationLevel') fields['verification_level'] = level.value - yield from self.http.edit_server(server.id, **fields) + yield from self.http.edit_guild(guild.id, **fields) @asyncio.coroutine - def get_bans(self, server): + def get_bans(self, guild): """|coro| Retrieves all the :class:`User` s that are banned from the specified - server. + guild. You must have proper permissions to get this information. Parameters ---------- - server : :class:`Server` - The server to get ban information from. + guild : :class:`Guild` + The guild to get ban information from. Raises ------- @@ -2394,14 +2394,14 @@ class Client: A list of :class:`User` that have been banned. """ - data = yield from self.http.get_bans(server.id) + data = yield from self.http.get_bans(guild.id) return [self.connection.try_insert_user(user) for user in data] @asyncio.coroutine - def prune_members(self, server, *, days): + def prune_members(self, guild, *, days): """|coro| - Prunes a :class:`Server` from its inactive members. + Prunes a :class:`Guild` from its inactive members. The inactive members are denoted if they have not logged on in ``days`` number of days and they have no roles. @@ -2413,8 +2413,8 @@ class Client: Parameters ----------- - server: :class:`Server` - The server to prune from. + guild: :class:`Guild` + The guild to prune from. days: int The number of days before counting as inactive. @@ -2436,21 +2436,21 @@ class Client: if not isinstance(days, int): raise InvalidArgument('Expected int for ``days``, received {0.__class__.__name__} instead.'.format(days)) - data = yield from self.http.prune_members(server.id, days) + data = yield from self.http.prune_members(guild.id, days) return data['pruned'] @asyncio.coroutine - def estimate_pruned_members(self, server, *, days): + def estimate_pruned_members(self, guild, *, days): """|coro| Similar to :meth:`prune_members` except instead of actually pruning members, it returns how many members it would prune - from the server had it been called. + from the guild had it been called. Parameters ----------- - server: :class:`Server` - The server to estimate a prune from. + guild: :class:`Guild` + The guild to estimate a prune from. days: int The number of days before counting as inactive. @@ -2472,25 +2472,25 @@ class Client: if not isinstance(days, int): raise InvalidArgument('Expected int for ``days``, received {0.__class__.__name__} instead.'.format(days)) - data = yield from self.http.estimate_pruned_members(server.id, days) + data = yield from self.http.estimate_pruned_members(guild.id, days) return data['pruned'] @asyncio.coroutine - def create_custom_emoji(self, server, *, name, image): + def create_custom_emoji(self, guild, *, name, image): """|coro| - Creates a custom :class:`Emoji` for a :class:`Server`. + Creates a custom :class:`Emoji` for a :class:`Guild`. This endpoint is only allowed for user bots or white listed bots. If this is done by a user bot then this is a local - emoji that can only be used inside that server. + emoji that can only be used inside that guild. - There is currently a limit of 50 local emotes per server. + There is currently a limit of 50 local emotes per guild. Parameters ----------- - server: :class:`Server` - The server to add the emoji to. + guild: :class:`Guild` + The guild to add the emoji to. name: str The emoji name. Must be at least 2 characters. image: bytes @@ -2511,14 +2511,14 @@ class Client: """ img = utils._bytes_to_base64_data(image) - data = yield from self.http.create_custom_emoji(server.id, name, img) - return Emoji(server=server, data=data, state=self.connection.ctx) + data = yield from self.http.create_custom_emoji(guild.id, name, img) + return Emoji(guild=guild, data=data, state=self.connection.ctx) @asyncio.coroutine def delete_custom_emoji(self, emoji): """|coro| - Deletes a custom :class:`Emoji` from a :class:`Server`. + Deletes a custom :class:`Emoji` from a :class:`Guild`. This follows the same rules as :meth:`create_custom_emoji`. @@ -2535,7 +2535,7 @@ class Client: An error occurred deleting the emoji. """ - yield from self.http.delete_custom_emoji(emoji.server.id, emoji.id) + yield from self.http.delete_custom_emoji(emoji.guild.id, emoji.id) @asyncio.coroutine def edit_custom_emoji(self, emoji, *, name): @@ -2558,22 +2558,22 @@ class Client: An error occurred editing the emoji. """ - yield from self.http.edit_custom_emoji(emoji.server.id, emoji.id, name=name) + yield from self.http.edit_custom_emoji(emoji.guild.id, emoji.id, name=name) # Invite management def _fill_invite_data(self, data): - server = self.connection._get_server(data['guild']['id']) - if server is not None: + guild = self.connection._get_guild(data['guild']['id']) + if guild is not None: ch_id = data['channel']['id'] - channel = server.get_channel(ch_id) + channel = guild.get_channel(ch_id) else: - server = Object(id=data['guild']['id']) - server.name = data['guild']['name'] + guild = Object(id=data['guild']['id']) + guild.name = data['guild']['name'] channel = Object(id=data['channel']['id']) channel.name = data['channel']['name'] - data['server'] = server + data['guild'] = guild data['channel'] = channel @asyncio.coroutine @@ -2581,12 +2581,12 @@ class Client: """|coro| Creates an invite for the destination which could be either a - :class:`Server` or :class:`Channel`. + :class:`Guild` or :class:`Channel`. Parameters ------------ destination - The :class:`Server` or :class:`Channel` to create the invite to. + The :class:`Guild` or :class:`Channel` to create the invite to. max_age : int How long the invite should last. If it's 0 then the invite doesn't expire. Defaults to 0. @@ -2622,7 +2622,7 @@ class Client: Note ------ - If the invite is for a server you have not joined, the server and channel + If the invite is for a guild you have not joined, the guild and channel attributes of the returned invite will be :class:`Object` with the names patched in. @@ -2650,17 +2650,17 @@ class Client: return Invite(**data) @asyncio.coroutine - def invites_from(self, server): + def invites_from(self, guild): """|coro| - Returns a list of all active instant invites from a :class:`Server`. + Returns a list of all active instant invites from a :class:`Guild`. You must have proper permissions to get this information. Parameters ---------- - server : :class:`Server` - The server to get invites from. + guild : :class:`Guild` + The guild to get invites from. Raises ------- @@ -2675,12 +2675,12 @@ class Client: The list of invites that are currently active. """ - data = yield from self.http.invites_from(server.id) + data = yield from self.http.invites_from(guild.id) result = [] for invite in data: - channel = server.get_channel(invite['channel']['id']) + channel = guild.get_channel(invite['channel']['id']) invite['channel'] = channel - invite['server'] = server + invite['guild'] = guild result.append(Invite(**invite)) return result @@ -2742,18 +2742,18 @@ class Client: # Role management @asyncio.coroutine - def move_role(self, server, role, position): + def move_role(self, guild, role, position): """|coro| - Moves the specified :class:`Role` to the given position in the :class:`Server`. + Moves the specified :class:`Role` to the given position in the :class:`Guild`. The :class:`Role` object is not directly modified afterwards until the corresponding WebSocket event is received. Parameters ----------- - server : :class:`Server` - The server the role belongs to. + guild : :class:`Guild` + The guild the role belongs to. role : :class:`Role` The role to edit. position : int @@ -2762,7 +2762,7 @@ class Client: Raises ------- InvalidArgument - If position is 0, or role is server.default_role + If position is 0, or role is guild.default_role Forbidden You do not have permissions to change role order. HTTPException @@ -2772,17 +2772,17 @@ class Client: if position == 0: raise InvalidArgument("Cannot move role to position 0") - if role == server.default_role: + if role == guild.default_role: raise InvalidArgument("Cannot move default role") if role.position == position: return # Save discord the extra request. - url = '{0}/{1.id}/roles'.format(self.http.GUILDS, server) + url = '{0}/{1.id}/roles'.format(self.http.GUILDS, guild) change_range = range(min(role.position, position), max(role.position, position) + 1) - roles = [r.id for r in sorted(filter(lambda x: (x.position in change_range) and x != role, server.roles), key=lambda x: x.position)] + roles = [r.id for r in sorted(filter(lambda x: (x.position in change_range) and x != role, guild.roles), key=lambda x: x.position)] if role.position > position: roles.insert(0, role.id) @@ -2793,15 +2793,15 @@ class Client: yield from self.http.patch(url, json=payload, bucket='move_role') @asyncio.coroutine - def edit_role(self, server, role, **fields): + def edit_role(self, guild, role, **fields): """|coro| - Edits the specified :class:`Role` for the entire :class:`Server`. + Edits the specified :class:`Role` for the entire :class:`Guild`. The :class:`Role` object is not directly modified afterwards until the corresponding WebSocket event is received. - All fields except ``server`` and ``role`` are optional. To change + All fields except ``guild`` and ``role`` are optional. To change the position of a role, use :func:`move_role` instead. .. versionchanged:: 0.8.0 @@ -2809,8 +2809,8 @@ class Client: Parameters ----------- - server : :class:`Server` - The server the role belongs to. + guild : :class:`Guild` + The guild the role belongs to. role : :class:`Role` The role to edit. name : str @@ -2844,18 +2844,18 @@ class Client: 'mentionable': fields.get('mentionable', role.mentionable) } - yield from self.http.edit_role(server.id, role.id, **payload) + yield from self.http.edit_role(guild.id, role.id, **payload) @asyncio.coroutine - def delete_role(self, server, role): + def delete_role(self, guild, role): """|coro| - Deletes the specified :class:`Role` for the entire :class:`Server`. + Deletes the specified :class:`Role` for the entire :class:`Guild`. Parameters ----------- - server : :class:`Server` - The server the role belongs to. + guild : :class:`Guild` + The guild the role belongs to. role : :class:`Role` The role to delete. @@ -2867,11 +2867,11 @@ class Client: Deleting the role failed. """ - yield from self.http.delete_role(server.id, role.id) + yield from self.http.delete_role(guild.id, role.id) @asyncio.coroutine def _replace_roles(self, member, roles): - yield from self.http.replace_roles(member.id, member.server.id, roles) + yield from self.http.replace_roles(member.id, member.guild.id, roles) @asyncio.coroutine def add_roles(self, member, *roles): @@ -2971,7 +2971,7 @@ class Client: yield from self._replace_roles(member, new_roles) @asyncio.coroutine - def create_role(self, server, **fields): + def create_role(self, guild, **fields): """|coro| Creates a :class:`Role`. @@ -2986,12 +2986,12 @@ class Client: is stored in cache. """ - data = yield from self.http.create_role(server.id) - role = Role(server=server, data=data, state=self.connection.ctx) + data = yield from self.http.create_role(guild.id) + role = Role(guild=guild, data=data, state=self.connection.ctx) # we have to call edit because you can't pass a payload to the # http request currently. - yield from self.edit_role(server, role, **fields) + yield from self.edit_role(guild, role, **fields) return role @asyncio.coroutine @@ -3002,7 +3002,7 @@ class Client: specified :class:`Channel`. The ``target`` parameter should either be a :class:`Member` or a - :class:`Role` that belongs to the channel's server. + :class:`Role` that belongs to the channel's guild. You must have the proper permissions to do this. @@ -3119,14 +3119,14 @@ class Client: if getattr(channel, 'type', ChannelType.text) != ChannelType.voice: raise InvalidArgument('The channel provided must be a voice channel.') - yield from self.http.move_member(member.id, member.server.id, channel.id) + yield from self.http.move_member(member.id, member.guild.id, channel.id) @asyncio.coroutine def join_voice_channel(self, channel): """|coro| Joins a voice channel and creates a :class:`VoiceClient` to - establish your connection to the voice server. + establish your connection to the voice guild. After this function is successfully called, :attr:`voice` is set to the returned :class:`VoiceClient`. @@ -3150,7 +3150,7 @@ class Client: Returns ------- :class:`VoiceClient` - A voice client that is fully connected to the voice server. + A voice client that is fully connected to the voice guild. """ if isinstance(channel, Object): channel = self.get_channel(channel.id) @@ -3158,24 +3158,24 @@ class Client: if getattr(channel, 'type', ChannelType.text) != ChannelType.voice: raise InvalidArgument('Channel passed must be a voice channel') - server = channel.server + guild = channel.guild - if self.is_voice_connected(server): - raise ClientException('Already connected to a voice channel in this server') + if self.is_voice_connected(guild): + raise ClientException('Already connected to a voice channel in this guild') log.info('attempting to join voice channel {0.name}'.format(channel)) def session_id_found(data): user_id = data.get('user_id') guild_id = data.get('guild_id') - return user_id == self.user.id and guild_id == server.id + return user_id == self.user.id and guild_id == guild.id # register the futures for waiting session_id_future = self.ws.wait_for('VOICE_STATE_UPDATE', session_id_found) - voice_data_future = self.ws.wait_for('VOICE_SERVER_UPDATE', lambda d: d.get('guild_id') == server.id) + voice_data_future = self.ws.wait_for('VOICE_SERVER_UPDATE', lambda d: d.get('guild_id') == guild.id) # request joining - yield from self.ws.voice_state(server.id, channel.id) + yield from self.ws.voice_state(guild.id, channel.id) session_id_data = yield from asyncio.wait_for(session_id_future, timeout=10.0, loop=self.loop) data = yield from asyncio.wait_for(voice_data_future, timeout=10.0, loop=self.loop) @@ -3199,37 +3199,37 @@ class Client: pass raise e # re-raise - self.connection._add_voice_client(server.id, voice) + self.connection._add_voice_client(guild.id, voice) return voice - def is_voice_connected(self, server): + def is_voice_connected(self, guild): """Indicates if we are currently connected to a voice channel in the - specified server. + specified guild. Parameters ----------- - server : :class:`Server` - The server to query if we're connected to it. + guild : :class:`Guild` + The guild to query if we're connected to it. """ - voice = self.voice_client_in(server) + voice = self.voice_client_in(guild) return voice is not None - def voice_client_in(self, server): - """Returns the voice client associated with a server. + def voice_client_in(self, guild): + """Returns the voice client associated with a guild. If no voice client is found then ``None`` is returned. Parameters ----------- - server : :class:`Server` - The server to query if we have a voice client for. + guild : :class:`Guild` + The guild to query if we have a voice client for. Returns -------- :class:`VoiceClient` - The voice client associated with the server. + The voice client associated with the guild. """ - return self.connection._get_voice_client(server.id) + return self.connection._get_voice_client(guild.id) def group_call_in(self, channel): """Returns the :class:`GroupCall` associated with a private channel. @@ -3276,7 +3276,7 @@ class Client: """|coro| Retrieves a :class:`User` based on their ID. This can only - be used by bot accounts. You do not have to share any servers + be used by bot accounts. You do not have to share any guilds with the user to get this information, however many operations do require that you do. |