@ -187,8 +187,6 @@ class Guild(Hashable):
. . versionadded : : 2.0
. . versionadded : : 2.0
afk_timeout : : class : ` int `
afk_timeout : : class : ` int `
The number of seconds until someone is moved to the AFK channel .
The number of seconds until someone is moved to the AFK channel .
afk_channel : Optional [ : class : ` VoiceChannel ` ]
The channel that denotes the AFK channel . ` ` None ` ` if it doesn ' t exist.
id : : class : ` int `
id : : class : ` int `
The guild ' s ID.
The guild ' s ID.
owner_id : : class : ` int `
owner_id : : class : ` int `
@ -251,13 +249,13 @@ class Guild(Hashable):
approximate_member_count : Optional [ : class : ` int ` ]
approximate_member_count : Optional [ : class : ` int ` ]
The approximate number of members in the guild . This is ` ` None ` ` unless the guild is obtained
The approximate number of members in the guild . This is ` ` None ` ` unless the guild is obtained
using : meth : ` Client . fetch_guild ` with ` ` with_counts = True ` ` .
using : meth : ` Client . fetch_guild ` or : meth : ` Client . fetch_guilds ` with ` ` with_counts = True ` ` .
. . versionadded : : 2.0
. . versionadded : : 2.0
approximate_presence_count : Optional [ : class : ` int ` ]
approximate_presence_count : Optional [ : class : ` int ` ]
The approximate number of members currently active in the guild .
The approximate number of members currently active in the guild .
Offline members are excluded . This is ` ` None ` ` unless the guild is obtained using
Offline members are excluded . This is ` ` None ` ` unless the guild is obtained using
: meth : ` Client . fetch_guild ` with ` ` with_counts = True ` ` .
: meth : ` Client . fetch_guild ` or : meth : ` Client . fetch_guilds ` with ` ` with_counts = True ` ` .
. . versionchanged : : 2.0
. . versionchanged : : 2.0
premium_progress_bar_enabled : : class : ` bool `
premium_progress_bar_enabled : : class : ` bool `
@ -268,11 +266,14 @@ class Guild(Hashable):
Indicates if the guild has widget enabled .
Indicates if the guild has widget enabled .
. . versionadded : : 2.0
. . versionadded : : 2.0
max_stage_video_users : Optional [ : class : ` int ` ]
The maximum amount of users in a stage video channel .
. . versionadded : : 2.3
"""
"""
__slots__ = (
__slots__ = (
' afk_timeout ' ,
' afk_timeout ' ,
' afk_channel ' ,
' name ' ,
' name ' ,
' id ' ,
' id ' ,
' unavailable ' ,
' unavailable ' ,
@ -295,6 +296,7 @@ class Guild(Hashable):
' vanity_url_code ' ,
' vanity_url_code ' ,
' widget_enabled ' ,
' widget_enabled ' ,
' _widget_channel_id ' ,
' _widget_channel_id ' ,
' _afk_channel_id ' ,
' _members ' ,
' _members ' ,
' _channels ' ,
' _channels ' ,
' _icon ' ,
' _icon ' ,
@ -316,12 +318,14 @@ class Guild(Hashable):
' approximate_member_count ' ,
' approximate_member_count ' ,
' approximate_presence_count ' ,
' approximate_presence_count ' ,
' premium_progress_bar_enabled ' ,
' premium_progress_bar_enabled ' ,
' _safety_alerts_channel_id ' ,
' max_stage_video_users ' ,
)
)
_PREMIUM_GUILD_LIMITS : ClassVar [ Dict [ Optional [ int ] , _GuildLimit ] ] = {
_PREMIUM_GUILD_LIMITS : ClassVar [ Dict [ Optional [ int ] , _GuildLimit ] ] = {
None : _GuildLimit ( emoji = 50 , stickers = 5 , bitrate = 96e3 , filesize = 26214400 ) ,
None : _GuildLimit ( emoji = 50 , stickers = 5 , bitrate = 96e3 , filesize = utils . DEFAULT_FILE_SIZE_LIMIT_BYTES ) ,
0 : _GuildLimit ( emoji = 50 , stickers = 5 , bitrate = 96e3 , filesize = 26214400 ) ,
0 : _GuildLimit ( emoji = 50 , stickers = 5 , bitrate = 96e3 , filesize = utils . DEFAULT_FILE_SIZE_LIMIT_BYTES ) ,
1 : _GuildLimit ( emoji = 100 , stickers = 15 , bitrate = 128e3 , filesize = 26214400 ) ,
1 : _GuildLimit ( emoji = 100 , stickers = 15 , bitrate = 128e3 , filesize = utils . DEFAULT_FILE_SIZE_LIMIT_BYTES ) ,
2 : _GuildLimit ( emoji = 150 , stickers = 30 , bitrate = 256e3 , filesize = 52428800 ) ,
2 : _GuildLimit ( emoji = 150 , stickers = 30 , bitrate = 256e3 , filesize = 52428800 ) ,
3 : _GuildLimit ( emoji = 250 , stickers = 60 , bitrate = 384e3 , filesize = 104857600 ) ,
3 : _GuildLimit ( emoji = 250 , stickers = 60 , bitrate = 384e3 , filesize = 104857600 ) ,
}
}
@ -479,6 +483,7 @@ class Guild(Hashable):
self . max_presences : Optional [ int ] = guild . get ( ' max_presences ' )
self . max_presences : Optional [ int ] = guild . get ( ' max_presences ' )
self . max_members : Optional [ int ] = guild . get ( ' max_members ' )
self . max_members : Optional [ int ] = guild . get ( ' max_members ' )
self . max_video_channel_users : Optional [ int ] = guild . get ( ' max_video_channel_users ' )
self . max_video_channel_users : Optional [ int ] = guild . get ( ' max_video_channel_users ' )
self . max_stage_video_users : Optional [ int ] = guild . get ( ' max_stage_video_channel_users ' )
self . premium_tier : int = guild . get ( ' premium_tier ' , 0 )
self . premium_tier : int = guild . get ( ' premium_tier ' , 0 )
self . premium_subscription_count : int = guild . get ( ' premium_subscription_count ' ) or 0
self . premium_subscription_count : int = guild . get ( ' premium_subscription_count ' ) or 0
self . vanity_url_code : Optional [ str ] = guild . get ( ' vanity_url_code ' )
self . vanity_url_code : Optional [ str ] = guild . get ( ' vanity_url_code ' )
@ -489,62 +494,53 @@ class Guild(Hashable):
self . _discovery_splash : Optional [ str ] = guild . get ( ' discovery_splash ' )
self . _discovery_splash : Optional [ str ] = guild . get ( ' discovery_splash ' )
self . _rules_channel_id : Optional [ int ] = utils . _get_as_snowflake ( guild , ' rules_channel_id ' )
self . _rules_channel_id : Optional [ int ] = utils . _get_as_snowflake ( guild , ' rules_channel_id ' )
self . _public_updates_channel_id : Optional [ int ] = utils . _get_as_snowflake ( guild , ' public_updates_channel_id ' )
self . _public_updates_channel_id : Optional [ int ] = utils . _get_as_snowflake ( guild , ' public_updates_channel_id ' )
self . _safety_alerts_channel_id : Optional [ int ] = utils . _get_as_snowflake ( guild , ' safety_alerts_channel_id ' )
self . nsfw_level : NSFWLevel = try_enum ( NSFWLevel , guild . get ( ' nsfw_level ' , 0 ) )
self . nsfw_level : NSFWLevel = try_enum ( NSFWLevel , guild . get ( ' nsfw_level ' , 0 ) )
self . mfa_level : MFALevel = try_enum ( MFALevel , guild . get ( ' mfa_level ' , 0 ) )
self . mfa_level : MFALevel = try_enum ( MFALevel , guild . get ( ' mfa_level ' , 0 ) )
self . approximate_presence_count : Optional [ int ] = guild . get ( ' approximate_presence_count ' )
self . approximate_presence_count : Optional [ int ] = guild . get ( ' approximate_presence_count ' )
self . approximate_member_count : Optional [ int ] = guild . get ( ' approximate_member_count ' )
self . approximate_member_count : Optional [ int ] = guild . get ( ' approximate_member_count ' )
self . premium_progress_bar_enabled : bool = guild . get ( ' premium_progress_bar_enabled ' , False )
self . premium_progress_bar_enabled : bool = guild . get ( ' premium_progress_bar_enabled ' , False )
self . owner_id : Optional [ int ] = utils . _get_as_snowflake ( guild , ' owner_id ' )
self . owner_id : Optional [ int ] = utils . _get_as_snowflake ( guild , ' owner_id ' )
self . _sync ( guild )
self . _large : Optional [ bool ] = None if self . _member_count is None else self . _member_count > = 250
self . _large : Optional [ bool ] = None if self . _member_count is None else self . _member_count > = 250
self . _afk_channel_id : Optional [ int ] = utils . _get_as_snowflake ( guild , ' afk_channel_id ' )
self . afk_channel : Optional [ VocalGuildChannel ] = self . get_channel ( utils . _get_as_snowflake ( guild , ' afk_channel_id ' ) ) # type: ignore
if ' channels ' in guild :
channels = guild [ ' channels ' ]
# TODO: refactor/remove?
def _sync ( self , data : GuildPayload ) - > None :
try :
self . _large = data [ ' large ' ]
except KeyError :
pass
if ' channels ' in data :
channels = data [ ' channels ' ]
for c in channels :
for c in channels :
factory , ch_type = _guild_channel_factory ( c [ ' type ' ] )
factory , ch_type = _guild_channel_factory ( c [ ' type ' ] )
if factory :
if factory :
self . _add_channel ( factory ( guild = self , data = c , state = self . _state ) ) # type: ignore
self . _add_channel ( factory ( guild = self , data = c , state = self . _state ) ) # type: ignore
for obj in data . get ( ' voice_states ' , [ ] ) :
for obj in guild . get ( ' voice_states ' , [ ] ) :
self . _update_voice_state ( obj , int ( obj [ ' channel_id ' ] ) )
self . _update_voice_state ( obj , int ( obj [ ' channel_id ' ] ) )
cache_joined = self . _state . member_cache_flags . joined
cache_joined = self . _state . member_cache_flags . joined
cache_voice = self . _state . member_cache_flags . voice
cache_voice = self . _state . member_cache_flags . voice
self_id = self . _state . self_id
self_id = self . _state . self_id
for mdata in data . get ( ' members ' , [ ] ) :
for mdata in guil d. get ( ' members ' , [ ] ) :
member = Member ( data = mdata , guild = self , state = self . _state ) # type: ignore # Members will have the 'user' key in this scenario
member = Member ( data = mdata , guild = self , state = self . _state ) # type: ignore # Members will have the 'user' key in this scenario
if cache_joined or member . id == self_id or ( cache_voice and member . id in self . _voice_states ) :
if cache_joined or member . id == self_id or ( cache_voice and member . id in self . _voice_states ) :
self . _add_member ( member )
self . _add_member ( member )
empty_tuple = ( )
empty_tuple = ( )
for presence in data . get ( ' presences ' , [ ] ) :
for presence in guil d. get ( ' presences ' , [ ] ) :
user_id = int ( presence [ ' user ' ] [ ' id ' ] )
user_id = int ( presence [ ' user ' ] [ ' id ' ] )
member = self . get_member ( user_id )
member = self . get_member ( user_id )
if member is not None :
if member is not None :
member . _presence_update ( presence , empty_tuple ) # type: ignore
member . _presence_update ( presence , empty_tuple ) # type: ignore
if ' threads ' in data :
if ' threads ' in guil d:
threads = data [ ' threads ' ]
threads = guil d[ ' threads ' ]
for thread in threads :
for thread in threads :
self . _add_thread ( Thread ( guild = self , state = self . _state , data = thread ) )
self . _add_thread ( Thread ( guild = self , state = self . _state , data = thread ) )
if ' stage_instances ' in data :
if ' stage_instances ' in guil d:
for s in data [ ' stage_instances ' ] :
for s in guil d[ ' stage_instances ' ] :
stage_instance = StageInstance ( guild = self , data = s , state = self . _state )
stage_instance = StageInstance ( guild = self , data = s , state = self . _state )
self . _stage_instances [ stage_instance . id ] = stage_instance
self . _stage_instances [ stage_instance . id ] = stage_instance
if ' guild_scheduled_events ' in data :
if ' guild_scheduled_events ' in guil d:
for s in data [ ' guild_scheduled_events ' ] :
for s in guil d[ ' guild_scheduled_events ' ] :
scheduled_event = ScheduledEvent ( data = s , state = self . _state )
scheduled_event = ScheduledEvent ( data = s , state = self . _state )
self . _scheduled_events [ scheduled_event . id ] = scheduled_event
self . _scheduled_events [ scheduled_event . id ] = scheduled_event
@ -763,6 +759,14 @@ class Guild(Hashable):
return emoji
return emoji
return None
return None
@property
def afk_channel ( self ) - > Optional [ VocalGuildChannel ] :
""" Optional[Union[:class:`VoiceChannel`, :class:`StageChannel`]]: The channel that denotes the AFK channel.
If no channel is set , then this returns ` ` None ` ` .
"""
return self . get_channel ( self . _afk_channel_id ) # type: ignore
@property
@property
def system_channel ( self ) - > Optional [ TextChannel ] :
def system_channel ( self ) - > Optional [ TextChannel ] :
""" Optional[:class:`TextChannel`]: Returns the guild ' s channel used for system messages.
""" Optional[:class:`TextChannel`]: Returns the guild ' s channel used for system messages.
@ -802,6 +806,17 @@ class Guild(Hashable):
channel_id = self . _public_updates_channel_id
channel_id = self . _public_updates_channel_id
return channel_id and self . _channels . get ( channel_id ) # type: ignore
return channel_id and self . _channels . get ( channel_id ) # type: ignore
@property
def safety_alerts_channel ( self ) - > Optional [ TextChannel ] :
""" Optional[:class:`TextChannel`]: Return ' s the guild ' s channel used for safety alerts, if set.
For example , this is used for the raid protection setting . The guild must have the ` ` COMMUNITY ` ` feature .
. . versionadded : : 2.3
"""
channel_id = self . _safety_alerts_channel_id
return channel_id and self . _channels . get ( channel_id ) # type: ignore
@property
@property
def widget_channel ( self ) - > Optional [ Union [ TextChannel , ForumChannel , VoiceChannel , StageChannel ] ] :
def widget_channel ( self ) - > Optional [ Union [ TextChannel , ForumChannel , VoiceChannel , StageChannel ] ] :
""" Optional[Union[:class:`TextChannel`, :class:`ForumChannel`, :class:`VoiceChannel`, :class:`StageChannel`]]: Returns
""" Optional[Union[:class:`TextChannel`, :class:`ForumChannel`, :class:`VoiceChannel`, :class:`StageChannel`]]: Returns
@ -1057,15 +1072,13 @@ class Guild(Hashable):
def get_member_named ( self , name : str , / ) - > Optional [ Member ] :
def get_member_named ( self , name : str , / ) - > Optional [ Member ] :
""" Returns the first member found that matches the name provided.
""" Returns the first member found that matches the name provided.
The name can have an optional discriminator argument , e . g . " Jake#0001 "
The name is looked up in the following order :
or " Jake " will both do the lookup . However the former will give a more
precise result . Note that the discriminator must have all 4 digits
for this to work .
If a nickname is passed , then it is looked up via the nickname . Note
- Username #Discriminator (deprecated)
however , that a nickname + discriminator combo will not lookup the nickname
- Username #0 (deprecated, only gets users that migrated from their discriminator)
but rather the username + discriminator combo due to nickname + discriminator
- Nickname
not being unique .
- Global name
- Username
If no member is found , ` ` None ` ` is returned .
If no member is found , ` ` None ` ` is returned .
@ -1073,10 +1086,14 @@ class Guild(Hashable):
` ` name ` ` parameter is now positional - only .
` ` name ` ` parameter is now positional - only .
. . deprecated : : 2.3
Looking up users via discriminator due to Discord API change .
Parameters
Parameters
- - - - - - - - - - -
- - - - - - - - - - -
name : : class : ` str `
name : : class : ` str `
The name of the member to lookup with an optional discriminator .
The name of the member to lookup .
Returns
Returns
- - - - - - - -
- - - - - - - -
@ -1085,22 +1102,19 @@ class Guild(Hashable):
then ` ` None ` ` is returned .
then ` ` None ` ` is returned .
"""
"""
result = None
members = self . members
members = self . members
if len ( name ) > 5 and name [ - 5 ] == ' # ' :
# The 5 length is checking to see if #0000 is in the string,
username , _ , discriminator = name . rpartition ( ' # ' )
# as a#0000 has a length of 6, the minimum for a potential
# discriminator lookup.
# If # isn't found then "discriminator" actually has the username
potential_discriminator = name [ - 4 : ]
if not username :
discriminator , username = username , discriminator
# do the actual lookup and return if found
# if it isn't found then we'll do a full name lookup below.
if discriminator == ' 0 ' or ( len ( discriminator ) == 4 and discriminator . isdigit ( ) ) :
result = utils . get ( members , name = name [ : - 5 ] , discriminator = potential_discriminator )
return utils . find ( lambda m : m . name == username and m . discriminator == discriminator , members )
if result is not None :
return result
def pred ( m : Member ) - > bool :
def pred ( m : Member ) - > bool :
return m . nick == name or m . name == name
return m . nick == name or m . global_name == name or m . name == name
return utils . find ( pred , members )
return utils . find ( pred , members )
@ -1304,7 +1318,7 @@ class Guild(Hashable):
nsfw : : class : ` bool `
nsfw : : class : ` bool `
To mark the channel as NSFW or not .
To mark the channel as NSFW or not .
news : : class : ` bool `
news : : class : ` bool `
Whether to create the text channel as a news channel .
Whether to create the text channel as a news channel .
. . versionadded : : 2.0
. . versionadded : : 2.0
default_auto_archive_duration : : class : ` int `
default_auto_archive_duration : : class : ` int `
@ -1821,6 +1835,8 @@ class Guild(Hashable):
widget_enabled : bool = MISSING ,
widget_enabled : bool = MISSING ,
widget_channel : Optional [ Snowflake ] = MISSING ,
widget_channel : Optional [ Snowflake ] = MISSING ,
mfa_level : MFALevel = MISSING ,
mfa_level : MFALevel = MISSING ,
raid_alerts_disabled : bool = MISSING ,
safety_alerts_channel : TextChannel = MISSING ,
) - > Guild :
) - > Guild :
r """ |coro|
r """ |coro|
@ -1935,6 +1951,18 @@ class Guild(Hashable):
reason : Optional [ : class : ` str ` ]
reason : Optional [ : class : ` str ` ]
The reason for editing this guild . Shows up on the audit log .
The reason for editing this guild . Shows up on the audit log .
raid_alerts_disabled : : class : ` bool `
Whether the alerts for raid protection should be disabled for the guild .
. . versionadded : : 2.3
safety_alerts_channel : Optional [ : class : ` TextChannel ` ]
The new channel that is used for safety alerts . This is only available to
guilds that contain ` ` COMMUNITY ` ` in : attr : ` Guild . features ` . Could be ` ` None ` ` for no
safety alerts channel .
. . versionadded : : 2.3
Raises
Raises
- - - - - - -
- - - - - - -
Forbidden
Forbidden
@ -1946,9 +1974,9 @@ class Guild(Hashable):
PNG or JPG . This is also raised if you are not the owner of the
PNG or JPG . This is also raised if you are not the owner of the
guild and request an ownership transfer .
guild and request an ownership transfer .
TypeError
TypeError
The type passed to the ` ` default_notifications ` ` , ` ` verification_lev el` ` ,
The type passed to the ` ` default_notifications ` ` , ` ` rules_channel ` ` , ` ` public_updates_chann el` ` ,
` ` explicit_content_filter ` ` , ` ` system_channel_flags ` ` , or ` ` mfa_level ` ` parameter was
` ` safety_alerts_channel ` ` ` ` verification_level ` ` , ` ` explicit_content_filter ` ` ,
of the incorrect type .
` ` system_channel_flags ` ` , or ` ` mfa_level ` ` parameter was of the incorrect type .
Returns
Returns
- - - - - - - -
- - - - - - - -
@ -2020,14 +2048,33 @@ class Guild(Hashable):
if rules_channel is None :
if rules_channel is None :
fields [ ' rules_channel_id ' ] = rules_channel
fields [ ' rules_channel_id ' ] = rules_channel
else :
else :
if not isinstance ( rules_channel , TextChannel ) :
raise TypeError ( f ' rules_channel must be of type TextChannel not { rules_channel . __class__ . __name__ } ' )
fields [ ' rules_channel_id ' ] = rules_channel . id
fields [ ' rules_channel_id ' ] = rules_channel . id
if public_updates_channel is not MISSING :
if public_updates_channel is not MISSING :
if public_updates_channel is None :
if public_updates_channel is None :
fields [ ' public_updates_channel_id ' ] = public_updates_channel
fields [ ' public_updates_channel_id ' ] = public_updates_channel
else :
else :
if not isinstance ( public_updates_channel , TextChannel ) :
raise TypeError (
f ' public_updates_channel must be of type TextChannel not { public_updates_channel . __class__ . __name__ } '
)
fields [ ' public_updates_channel_id ' ] = public_updates_channel . id
fields [ ' public_updates_channel_id ' ] = public_updates_channel . id
if safety_alerts_channel is not MISSING :
if safety_alerts_channel is None :
fields [ ' safety_alerts_channel_id ' ] = safety_alerts_channel
else :
if not isinstance ( safety_alerts_channel , TextChannel ) :
raise TypeError (
f ' safety_alerts_channel must be of type TextChannel not { safety_alerts_channel . __class__ . __name__ } '
)
fields [ ' safety_alerts_channel_id ' ] = safety_alerts_channel . id
if owner is not MISSING :
if owner is not MISSING :
if self . owner_id != self . _state . self_id :
if self . owner_id != self . _state . self_id :
raise ValueError ( ' To transfer ownership you must be the owner of the guild. ' )
raise ValueError ( ' To transfer ownership you must be the owner of the guild. ' )
@ -2052,7 +2099,7 @@ class Guild(Hashable):
fields [ ' system_channel_flags ' ] = system_channel_flags . value
fields [ ' system_channel_flags ' ] = system_channel_flags . value
if any ( feat is not MISSING for feat in ( community , discoverable , invites_disabled ) ) :
if any ( feat is not MISSING for feat in ( community , discoverable , invites_disabled , raid_alerts_disabled ) ) :
features = set ( self . features )
features = set ( self . features )
if community is not MISSING :
if community is not MISSING :
@ -2078,6 +2125,12 @@ class Guild(Hashable):
else :
else :
features . discard ( ' INVITES_DISABLED ' )
features . discard ( ' INVITES_DISABLED ' )
if raid_alerts_disabled is not MISSING :
if raid_alerts_disabled :
features . add ( ' RAID_ALERTS_DISABLED ' )
else :
features . discard ( ' RAID_ALERTS_DISABLED ' )
fields [ ' features ' ] = list ( features )
fields [ ' features ' ] = list ( features )
if premium_progress_bar_enabled is not MISSING :
if premium_progress_bar_enabled is not MISSING :
@ -3433,7 +3486,6 @@ class Guild(Hashable):
data = await self . _state . http . create_role ( self . id , reason = reason , * * fields )
data = await self . _state . http . create_role ( self . id , reason = reason , * * fields )
role = Role ( guild = self , data = data , state = self . _state )
role = Role ( guild = self , data = data , state = self . _state )
# TODO: add to cache
return role
return role
async def edit_role_positions ( self , positions : Mapping [ Snowflake , int ] , * , reason : Optional [ str ] = None ) - > List [ Role ] :
async def edit_role_positions ( self , positions : Mapping [ Snowflake , int ] , * , reason : Optional [ str ] = None ) - > List [ Role ] :