Passed
Pull Request — main (#275)
by
unknown
01:46
created

pincer.objects.guild.guild   F

Complexity

Total Complexity 73

Size/Duplication

Total Lines 1774
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 73
eloc 564
dl 0
loc 1774
rs 2.56
c 0
b 0
f 0

53 Methods

Rating   Name   Duplication   Size   Complexity  
A Guild.get_audit_log() 0 14 1
A Guild.edit_role_position() 0 30 2
A Guild.delete_template() 0 23 1
A Guild.get_widget_settings() 0 14 1
A Guild.create_role() 0 47 1
A Guild.from_dict() 0 22 2
A Guild.prune_count() 0 26 1
A Guild.modify_member() 0 34 1
A Guild.add_guild_member_role() 0 13 1
A Guild.unban() 0 14 1
A Guild.delete() 0 5 1
A Guild.get_ban() 0 18 1
A Guild.edit_template() 0 36 1
A Guild.get_bans() 0 12 2
A Guild.prune() 0 38 1
A Guild.modify_channel_positions() 0 3 1
A Guild.create_channel() 0 41 1
A Guild.modify_widget() 0 27 1
A Guild.get_widget() 0 5 1
A Guild.get_roles() 0 12 2
A Guild.get_integrations() 0 13 2
A Guild.delete_role() 0 15 1
A Guild.modify_welcome_screen() 0 39 1
A Guild.create_emoji() 0 42 1
A Guild.create_template() 0 30 1
A Guild.edit_role() 0 49 1
A Guild.from_id() 0 23 1
A Guild.list_guild_members() 0 14 1
A Guild.get_member() 0 15 1
A Guild.edit_emoji() 0 38 1
A Guild.modify_current_user_voice_state() 0 34 1
A Guild.get_widget_image() 0 35 1
A Guild.get_invites() 0 13 2
A Guild.edit() 0 83 1
A Guild.search_guild_members() 0 21 2
A Guild.get_emoji() 0 18 1
A Guild.get_templates() 0 13 2
A Guild.preview() 0 11 1
A Guild.modify_current_member() 0 12 1
A Guild.remove_guild_member() 0 10 1
A Guild.delete_integration() 0 19 1
A Guild.remove_guild_member_role() 0 14 1
A Guild.get_voice_regions() 0 12 2
A Guild.ban() 0 30 3
A Guild.delete_emoji() 0 20 1
A Guild.sync_template() 0 23 1
A Guild.vanity_url() 0 14 1
A Guild.kick() 0 19 2
A Guild.get_welcome_screen() 0 10 1
A Guild.get_emojis() 0 13 2
A Guild.modify_user_voice_state() 0 34 1
A Guild.add_guild_member() 0 9 2
A Guild.list_active_threads() 0 11 1

How to fix   Complexity   

Complexity

Complex classes like pincer.objects.guild.guild often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
coding-style introduced by
Too many lines in module (1773/1000)
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from __future__ import annotations
5
6
from dataclasses import dataclass, field
7
from enum import IntEnum
8
from typing import AsyncGenerator, overload, TYPE_CHECKING
9
10
from ...exceptions import UnavailableGuildError
11
from ...utils.api_object import APIObject
12
from ...utils.conversion import construct_client_dict, remove_none
13
from ...utils.types import MISSING
14
15
if TYPE_CHECKING:
16
    from typing import Any, Dict, List, Optional, Tuple, Union
17
    from .channel import PublicThread, PrivateThread
18
19
    from .audit_log import AuditLog
20
    from .ban import Ban
21
    from .channel import Channel
22
    from .invite import Invite
23
    from .member import GuildMember
24
    from .features import GuildFeature
25
    from .overwrite import Overwrite
26
    from .role import Role
27
    from .stage import StageInstance
28
    from .template import GuildTemplate
29
    from .welcome_screen import WelcomeScreen, WelcomeScreenChannel
30
    from .widget import GuildWidget
31
    from ..user.user import User
32
    from ..user.integration import Integration
33
    from ..voice.region import VoiceRegion
34
    from ..events.presence import PresenceUpdateEvent
35
    from ..message.emoji import Emoji
36
    from ..message.sticker import Sticker
37
    from ..user.voice_state import VoiceState
38
    from ...client import Client
39
    from ...utils.timestamp import Timestamp
40
    from ...utils.types import APINullable, JSONSerializable
41
    from ...utils.snowflake import Snowflake
42
43
44
class PremiumTier(IntEnum):
45
    """Represents the boost tier of a guild.
46
    Attributes
47
    ----------
48
    NONE:
49
        Guild has not unlocked any Server Boost perks.
50
    TIER_1:
51
        Guild has unlocked Server Boost level 1 perks.
52
    TIER_2:
53
        Guild has unlocked Server Boost level 2 perks.
54
    TIER_3:
55
        Guild has unlocked Server Boost level 3 perks.
56
    """
57
58
    NONE = 0
59
    TIER_1 = 1
60
    TIER_2 = 2
61
    TIER_3 = 3
62
63
64
class GuildNSFWLevel(IntEnum):
65
    """Represents the NSFW level of a guild.
66
    Attributes
67
    ----------
68
    DEFAULT:
69
        Default NSFW level.
70
    EXPLICIT:
71
        Explicit NSFW level.
72
    SAFE:
73
        SAFE NSFW level.
74
    AGE_RESTRICTED:
75
        Age restricted NSFW level.
76
    """
77
78
    DEFAULT = 0
79
    EXPLICIT = 1
80
    SAFE = 2
81
    AGE_RESTRICTED = 3
82
83
84
class ExplicitContentFilterLevel(IntEnum):
85
    """Represents the filter content level of a guild.
86
    Attributes
87
    ----------
88
    DISABLED:
89
        Media content will not be scanned.
90
    MEMBERS_WITHOUT_ROLES:
91
        Media content sent by members without roles will be scanned.
92
    ALL_MEMBERS:
93
        Media content sent by all members will be scanned.
94
    """
95
96
    DISABLED = 0
97
    MEMBERS_WITHOUT_ROLES = 1
98
    ALL_MEMBERS = 2
99
100
101
class MFALevel(IntEnum):
102
    """Represents the multi factor authentication level of a guild.
103
    Attributes
104
    ----------
105
    NONE:
106
        Guild has no MFA/2FA requirement for moderation actions.
107
    ELEVATED:
108
        Guild has a 2FA requirement for moderation actions
109
    """
110
111
    NONE = 0
112
    ELEVATED = 1
113
114
115
class VerificationLevel(IntEnum):
116
    """Represents the verification level of a guild.
117
    Attributes
118
    ----------
119
    NONE:
120
        Unrestricted.
121
    LOW:
122
        Must have verified email on account.
123
    MEDIUM:
124
        Must be registered on Discord for longer than 5 minutes.
125
    HIGH:
126
        Must be a member of the server for longer than 10 minutes.
127
    VERY_HIGH:
128
        Must have a verified phone number.
129
    """
130
131
    NONE = 0
132
    LOW = 1
133
    MEDIUM = 2
134
    HIGH = 3
135
    VERY_HIGH = 4
136
137
138
class DefaultMessageNotificationLevel(IntEnum):
139
    """Represents the default message notification level of a guild.
140
    Attributes
141
    ----------
142
    ALL_MESSAGES:
143
        Members will receive notifications for all messages by default.
144
    ONLY_MENTIONS:
145
        Members will receive notifications only for messages that @mention them by default.
146
    """
147
148
    # noqa: E501
149
    ALL_MESSAGES = 0
150
    ONLY_MENTIONS = 1
151
152
153
class SystemChannelFlags(IntEnum):
154
    """Represents the system channel flags of a guild.
155
    Attributes
156
    ----------
157
    SUPPRESS_JOIN_NOTIFICATIONS:
158
        Suppress member join notifications.
159
    SUPPRESS_PREMIUM_SUBSCRIPTIONS:
160
        Suppress server boost notifications.
161
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS:
162
        Suppress server setup tips.
163
    SUPPRESS_JOIN_NOTIFICATION_REPLIES:
164
        Hide member join sticker reply buttons
165
    """
166
167
    SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0
168
    SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
169
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS = 1 << 2
170
    SUPPRESS_JOIN_NOTIFICATION_REPLIES = 1 << 3
171
172
173
@dataclass
174
class GuildPreview(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (10/7)
Loading history...
175
    """Represents a guild preview.
176
    Attributes
177
    ----------
178
    id: :class:`Snowflake`
179
        The guild ID.
180
    name: :class:`str`
181
        The guild name.
182
    icon: :class:`str`
183
        The guild icon hash.
184
    splash: :class:`str`
185
        The guild splash hash.
186
    discovery_splash: :class:`str`
187
        The guild discovery splash hash.
188
    emojis: :class:`List[Emoji]`
189
        The guild emojis.
190
    features: :class:`List[GuildFeature]`
191
        The guild features.
192
    approximate_member_count: :class:`int`
193
        The approximate member count.
194
    approximate_presence_count: :class:`int`
195
        The approximate number of online members in this guild
196
    description: :class:`str`
197
        The guild description.
198
    """
199
200
    id: Snowflake
201
    name: str
202
    emojis: List[Emoji]
203
    features: List[GuildFeature]
204
    approximate_member_count: int
205
    approximate_presence_count: int
206
207
    icon: APINullable[str] = MISSING
208
    splash: APINullable[str] = MISSING
209
    discovery_splash: APINullable[str] = MISSING
210
    description: APINullable[str] = MISSING
211
212
213
@dataclass
214
class Guild(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (59/7)
Loading history...
best-practice introduced by
Too many public methods (53/20)
Loading history...
215
    """Represents a Discord guild/server in which your client resides.
216
    Attributes
217
    ----------
218
    afk_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
219
        Id of afk channel
220
    afk_timeout: :class:`int`
221
        Afk timeout in seconds
222
    application_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
223
        Application id of the guild creator if it is bot-created
224
    banner: Optional[:class:`str`]
225
        Banner hash
226
    default_message_notifications: :class:`~pincer.objects.guild.guild.DefaultMessageNotificationLevel`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
227
        Default message notifications level
228
    description: Optional[:class:`str`]
229
        The description of a Community guild
230
    discovery_splash: Optional[:class:`str`]
231
        Discovery splash hash;
232
        only present for guilds with the "DISCOVERABLE" feature
233
    emojis: List[:class:`~pincer.objects.message.emoji.Emoji`]
234
        Custom guild emojis
235
    explicit_content_filter: :class:`~pincer.objects.guild.guild.ExplicitContentFilterLevel`
236
        Explicit content filter level
237
    features: List[:class:`~pincer.objects.guild.features.GuildFeature`]
238
        Enabled guild features
239
    id: :class:`~pincer.utils.snowflake.Snowflake`
240
        Guild id
241
    icon: Optional[:class:`str`]
242
        Icon hash
243
    mfa_level: :class:`~pincer.objects.guild.guild.MFALevel`
244
        Required MFA level for the guild
245
    name: :class:`str`
246
        Guild name (2-100 characters, excluding trailing and leading
247
        whitespace)
248
    nsfw_level: :class:`~pincer.objects.guild.guild.NSFWLevel`
249
        Guild NSFW level
250
    owner_id: :class:`~pincer.utils.snowflake.Snowflake`
251
        Id of owner
252
    preferred_locale: :class:`str`
253
        The preferred locale of a Community guild;
254
        used in server discovery and notices from Discord;
255
        defaults to "en-US"
256
    premium_tier: :class:`~pincer.objects.guild.guild.PremiumTier`
257
        Premium tier (Server Boost level)
258
    public_updates_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
259
        The id of the channel where admins
260
        and moderators of Community guilds receive notices from Discord
261
    roles: List[:class:`~pincer.objects.guild.role.Role`]
262
        Roles in the guild
263
    rules_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
264
        The id of the channel where Community guilds can display rules
265
        and/or guidelines
266
    splash: Optional[:class:`str`]
267
        Splash hash
268
    system_channel_flags: :class:`~pincer.objects.guild.guild.SystemChannelFlags`
269
        System channel flags
270
    system_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
271
        The id of the channel where guild notices
272
        such as welcome messages and boost events are posted
273
    vanity_url_code: Optional[:class:`str`]
274
        The vanity url code for the guild
275
    verification_level: :class:`~pincer.objects.guild.guild.VerificationLevel`
276
        Verification level required for the guild
277
    approximate_member_count: APINullable[:class:`int`]
278
        Approximate number of members in this guild, returned from the
279
        `GET /guilds/<id>` endpoint when with_counts is true
280
    approximate_presence_count: APINullable[:class:`int`]
281
        Approximate number of non-offline members in this guild,
282
        returned from the `GET /guilds/<id>`
283
        endpoint when with_counts is true
284
    channels: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
285
        Channels in the guild
286
    icon_hash: APINullable[Optional[:class:`str`]]
287
        Icon hash, returned when in the template object
288
    joined_at: APINullable[:class:`~pincer.utils.timestamp.Timestamp`]
289
        When this guild was joined at
290
    large: APINullable[:class:`bool`]
291
        True if this is considered a large guild
292
    max_members: APINullable[:class:`int`]
293
        The maximum number of members for the guild
294
    max_presences: APINullable[Optional[:class:`int`]]
295
        The maximum number of presences for the guild
296
        (null is always returned, apart from the largest of guilds)
297
    max_video_channel_users: APINullable[:class:`int`]
298
        The maximum amount of users in a video channel
299
    members: APINullable[List[:class:`~pincer.objects.guild.member.GuildMember`]]
300
        Users in the guild
301
    member_count: APINullable[:class:`bool`]
302
        Total number of members in this guild
303
    nsfw: APINullable[:class:`bool`]
304
        Boolean if the server is NSFW
305
    owner: APINullable[:class:`bool`]
306
        True if the user is the owner of the guild
307
    permissions: APINullable[:class:`str`]
308
        Total permissions for the user in the guild
309
        (excludes overwrites)
310
    premium_subscription_count: APINullable[:class:`int`]
311
        The number of boosts this guild currently has
312
    presences: APINullable[List[:class:`~pincer.objects.events.presence.PresenceUpdateEvent`]]
313
        Presences of the members in the guild,
314
        will only include non-offline members if the size is greater
315
        than large threshold
316
    stage_instances: APINullable[List[:class:`~pincer.objects.guild.stage.StageInstance`]]
317
        Stage instances in the guild
318
    stickers: Optional[List[:class:`~pincer.objects.message.sticker.Sticker`]]
319
        Custom guild stickers
320
    region: APINullable[Optional[:class:`str`]]
321
        Voice region id for the guild (deprecated)
322
    threads: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
323
        All active threads in the guild that current user
324
        has permission to view
325
    unavailable: APINullable[:class:`bool`]
326
        True if this guild is unavailable due to an outage
327
    voice_states: APINullable[List[:class:`~pincer.objects.user.voice_state.VoiceState`]]
328
        States of members currently in voice channels;
329
        lacks the guild_id key
330
    widget_enabled: APINullable[:class:`bool`]
331
        True if the server widget is enabled
332
    widget_channel_id: APINullable[Optional[:class:`~pincer.utils.snowflake.Snowflake`]]
333
        The channel id that the widget will generate an invite to,
334
        or null if set to no invite
335
    welcome_screen: APINullable[:class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`]
336
        The welcome screen of a Community guild, shown to new members,
337
        returned in an Invite's guild object
338
    """
339
340
    # noqa: E501
341
    afk_timeout: int
342
    default_message_notifications: DefaultMessageNotificationLevel
343
    emojis: List[Emoji]
344
    explicit_content_filter: ExplicitContentFilterLevel
345
    features: List[GuildFeature]
346
    id: Snowflake
347
    mfa_level: MFALevel
348
    name: str
349
    nsfw_level: GuildNSFWLevel
350
    owner_id: Snowflake
351
    preferred_locale: str
352
    premium_tier: PremiumTier
353
    roles: List[Role]
354
    system_channel_flags: SystemChannelFlags
355
    verification_level: VerificationLevel
356
357
    guild_scheduled_events: APINullable[List] = MISSING
358
    lazy: APINullable[bool] = MISSING
359
    premium_progress_bar_enabled: APINullable[bool] = MISSING
360
    guild_hashes: APINullable[Dict] = MISSING
361
    afk_channel_id: APINullable[Snowflake] = MISSING
362
    application_id: APINullable[Snowflake] = MISSING
363
    embedded_activities: APINullable[List] = MISSING
364
    banner: APINullable[str] = MISSING
365
    description: APINullable[str] = MISSING
366
    discovery_splash: APINullable[str] = MISSING
367
    icon: APINullable[str] = MISSING
368
    public_updates_channel_id: APINullable[Snowflake] = MISSING
369
    rules_channel_id: APINullable[Snowflake] = MISSING
370
    splash: APINullable[str] = MISSING
371
    system_channel_id: APINullable[Snowflake] = MISSING
372
    vanity_url_code: APINullable[str] = MISSING
373
374
    application_command_counts: APINullable[Dict] = MISSING
375
    application_command_count: APINullable[int] = MISSING
376
    approximate_member_count: APINullable[int] = MISSING
377
    approximate_presence_count: APINullable[int] = MISSING
378
    channels: APINullable[List[Channel]] = field(default_factory=list)
379
    # TODO: Add type when type is known
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
380
    hub_type: APINullable[Any] = MISSING
381
    icon_hash: APINullable[Optional[str]] = MISSING
382
    joined_at: APINullable[Timestamp] = MISSING
383
    large: APINullable[bool] = MISSING
384
    max_members: APINullable[int] = MISSING
385
    max_presences: APINullable[Optional[int]] = MISSING
386
    max_video_channel_users: APINullable[int] = MISSING
387
    members: APINullable[List[GuildMember]] = MISSING
388
    member_count: APINullable[bool] = MISSING
389
    nsfw: APINullable[bool] = MISSING
390
    # Note: This is missing from discord's docs but in the api
391
    owner: APINullable[bool] = MISSING
392
    permissions: APINullable[str] = MISSING
393
    premium_subscription_count: APINullable[int] = MISSING
394
    presences: APINullable[List[PresenceUpdateEvent]] = MISSING
395
    stage_instances: APINullable[List[StageInstance]] = MISSING
396
    stickers: APINullable[List[Sticker]] = MISSING
397
    region: APINullable[Optional[str]] = MISSING
398
    threads: APINullable[List[Channel]] = MISSING
399
    # Guilds are considered available unless otherwise specified
400
    unavailable: APINullable[bool] = False
401
    voice_states: APINullable[List[VoiceState]] = MISSING
402
    widget_enabled: APINullable[bool] = MISSING
403
    widget_channel_id: APINullable[Optional[Snowflake]] = MISSING
404
    welcome_screen: APINullable[WelcomeScreen] = MISSING
405
406
    @classmethod
407
    async def from_id(cls, client: Client, _id: Union[int, Snowflake]) -> Guild:
408
        """
409
        Parameters
410
        ----------
411
        client : :class:`~pincer.Client`
412
            Client object to use the http gateway from.
413
        _id : :class:`pincer.utils.snowflake.Snowflake`
414
            Guild ID.
415
        Returns
416
        -------
417
        :class:`~pincer.objects.guild.guild.Guild`
418
            The new guild object.
419
        """
420
        data = await client.http.get(f"/guilds/{_id}")
421
        channel_data = await client.http.get(f"/guilds/{_id}/channels")
422
423
        data["channels"]: List[Channel] = [
424
            Channel.from_dict({**i, "_client": client, "_http": client.http})
425
            for i in (channel_data or [])
426
        ]
427
428
        return Guild.from_dict(construct_client_dict(client, data))
429
430
    async def get_member(self, _id: int) -> GuildMember:
431
        """|coro|
432
        Fetches a GuildMember from its identifier
433
434
        Parameters
435
        ----------
436
        _id: int
437
            The id of the guild member which should be fetched from the Discord
438
            gateway.
439
        Returns
440
        -------
441
        :class:`~pincer.objects.guild.member.GuildMember`
442
            A GuildMember object.
443
        """
444
        return await GuildMember.from_id(self._client, self.id, _id)
445
446
    @overload
447
    async def modify_member(
448
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
449
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
450
        _id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
451
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
452
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
453
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
454
        deaf: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
455
        channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
456
    ) -> GuildMember:
457
        """|coro|
458
        Modifies a member in the guild from its identifier and based on the
459
        keyword arguments provided.
460
        Parameters
461
        ----------
462
        _id : int
463
            Id of the member to modify
464
        nick : Optional[:class:`str`]
465
            New nickname for the member |default| :data:`None`
466
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake]]
467
            New roles for the member |default| :data:`None`
468
        mute : Optional[:class:`bool`]
469
            Whether the member is muted |default| :data:`None`
470
        deaf : Optional[:class:`bool`]
471
            Whether the member is deafened |default| :data:`None`
472
        channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake]
473
            Voice channel id to move to |default| :data:`None`
474
        Returns
475
        -------
476
        :class:`~pincer.objects.guild.member.GuildMember`
477
            The new member object.
478
        """
479
        ...
480
481
    async def modify_member(self, _id: int, **kwargs) -> GuildMember:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
482
        data = await self._http.patch(
483
            f"guilds/{self.id}/members/{_id}", data=kwargs
484
        )
485
        return GuildMember.from_dict(construct_client_dict(self._client, data))
486
487
      
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
488
    @overload
489
    async def create_channel(self, name: str,
0 ignored issues
show
best-practice introduced by
Too many arguments (11/5)
Loading history...
490
                             type: Optional[int] = None,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
491
                             topic: Optional[str] = None,
492
                             bitrate: Optional[int] = None,
493
                             user_limit: Optional[int] = None,
494
                             rate_limit_per_user: Optional[int] = None,
495
                             position: Optional[int] = None,
496
                             permission_overwrites: Optional[
497
                                 List[Overwrite]] = None,
498
                             parent_id: Optional[Snowflake] = None,
499
                             nsfw: Optional[bool] = None) -> Channel:
500
        """|coro|
501
        Create a new channel object for the guild.
502
503
        Parameters
504
        ----------
505
        name : str
506
            channel name (1-100 characters)
507
        type : Optional[:class:int`]
508
            the type of channel
509
        topic : Optional[:class:str`]
510
            channel topic (0-1024 characters)
511
        bitrate : Optional[:class:`int`]
512
            the bitrate (in bits) of the voice channel (voice only)
513
        user_limit : Optional[:class:`int`]
514
            the user limit of the voice channel (voice only)
515
        rate_limit_per_user : Optional[:class:`int`]
516
            amount of seconds a user has to wait before sending another message (0-21600)
517
            bots, as well as users with the permission manage_messages or manage_channel, are unaffected
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
518
        position : Optional[:class:`int`]
519
            sorting position of the channel
520
        permission_overwrites : Optional[List[:class:`~pincer.objects.guild.overwrite.Overwrite`]]
521
            the channel's permission overwrites
522
        parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
523
            id of the parent category for a channel
524
        nsfw : Optional[:class:`bool`]
525
            whether the channel is nsfw
526
527
        """
528
        ...
529
530
    async def create_channel(self, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
531
        data = await self._http.post(f"guilds/{self.id}/channels", data=kwargs)
532
        return Channel.from_dict(construct_client_dict(self._client, data=data))
533
534
    async def modify_channel_positions(
535
            self, *channel: Dict[str, Optional[Union[int, bool, Snowflake]]]):
536
        """|coro|
537
        Create a new channel object for the guild.
538
539
        Parameters
540
        ----------
541
542
        \*channel : Dict[str, Optional[Union[int, bool, :class:`~pincer.utils.snowflake.Snowflake`]
543
            Keys:
544
                - id : :class:`~pincer.utils.snowflake.Snowflake`
545
                - position : Optional[:class:`int`]
546
                - lock_permissions : Optional[:class:`bool`]
547
                - parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
548
549
        """
550
551
    async def list_active_threads(self) -> Tuple[
552
        List[Union[PublicThread, PrivateThread]], List[GuildMember]]:
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
553
        """|coro|
554
        Returns all active threads in the guild, including public and private threads.
555
        """
556
        data = await self._http.get(f"guilds/{self.id}/threads/active")
557
558
        threads = [Channel.from_dict(channel) for channel in data["threads"]]
559
        members = [GuildMember.from_dict(member) for member in data["members"]]
560
561
        return threads, members
562
563
    async def list_guild_members(self, limit: int = 1, after: int = 0):
564
        """|coro|
565
        Returns a list of guild member objects that are members of the guild.
566
567
        Parameters
568
        ----------
569
        limit : int
570
            max number of members to return (1-1000) |default| :data:`1`
571
        after : int
572
            the highest user id in the previous page |default| :data:`0`
573
        """
574
575
        return await self._http.get(
576
            f"guilds/{self.id}/members?limit={limit}&after={after}"
577
        )
578
579
    async def search_guild_members(self, query: str,
580
                                   limit: Optional[int] = None
581
                                   ) -> List[GuildMember]:
582
        """|coro|
583
        Returns a list of guild member objects whose username or nickname starts with a provided string.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
584
585
        Parameters
586
        ----------
587
        query : str
588
            Query string to match username(s) and nickname(s) against.
589
        limit : Optional[int]
590
            max number of members to return (1-1000) |default| :data:`1`
591
592
        """
593
594
        data = await self._http.get(
595
            f"guilds/{id}/members/search?query={query}"
596
            f"&{limit}" if limit else ""
597
        )
598
599
        return [GuildMember.from_dict(member) for member in data]
600
601
    @overload
602
    async def add_guild_member(self, *, user_id: Snowflake,
603
                               access_token: str,
604
                               nick: Optional[str] = None,
605
                               roles: Optional[List[Snowflake]] = None,
606
                               mute: Optional[bool] = None,
607
                               deaf: Optional[bool] = None
608
                               ) -> Optional[GuildMember]:
609
        """|coro|
610
        Adds a user to the guild, provided you have a valid oauth2 access token for the user with the guilds.join scope.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (120/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
611
612
        Parameters
613
        ----------
614
        user_id : str
615
            id of the user to be added
616
        access_token : str
617
            an oauth2 access token granted with the guilds.join to the bot's application for the user you want to add to the guild
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (130/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
618
        nick : Optional[str]
619
        	value to set users nickname to
620
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
621
        	array of role ids the member is assigned
622
        mute : Optional[bool]
623
        	whether the user is muted in voice channels
624
        deaf : Optional[bool]
625
        	whether the user is deafened in voice channels
626
627
        Returns
628
        -------
629
        :class:`~pincer.objects.guild.member.GuildMember`
630
            If the user is not in the guild
631
        None
632
            If the user is in the guild
633
        """
634
635
    async def add_guild_member(self, user_id, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
636
        data = self._http.put(f"guilds/{self.id}/members/{user_id}",
637
                              data=kwargs)
638
639
        return GuildMember.from_dict(data) if data else None
640
641
    async def modify_current_member(self, nick: str) -> GuildMember:
642
        """|coro|
643
        Modifies the current member in a guild.
644
645
        Parameters
646
        ----------
647
        nick : str
648
            value to set users nickname to
649
        """
650
        data = self._http.patch(f"guilds/{self.id}/members/@me", {"nick": nick})
651
        member = GuildMember.from_dict(data)
652
        return member
653
654
    async def add_guild_member_role(self, user_id: int, role_id: int) -> None:
655
        """|coro|
656
        Adds a role to a guild member.
657
658
        Parameters
659
        ----------
660
        user_id : int
661
            id of the user to give a role to
662
        role_id : int
663
            id of a role
664
        """
665
        data = await self._http.put(
0 ignored issues
show
Unused Code introduced by
The variable data seems to be unused.
Loading history...
666
            f"guilds/{self.id}/{user_id}/roles/{role_id}", {})
667
        # TODO: remove the blank dictionary once #233 is fixed
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
668
669
    async def remove_guild_member_role(self, user_id: int,
670
                                       role_id: int) -> None:
671
        """|coro|
672
        Removes a role to a guild member.
673
674
        Parameters
675
        ----------
676
        user_id : int
677
            id of the user to remove a role from
678
        role_id : int
679
            id of a role
680
        """
681
        await self._http.delete(f"guilds/{self.id}/{user_id}/roles/{role_id}",
682
                                {})
683
        # TODO: remove the blank dictionary and format once #233 is fixed
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
684
685
    async def remove_guild_member(self, user_id: int) -> None:
686
        """|coro|
687
        Remove a member from a guild.
688
689
        Parameters
690
        ----------
691
        user_id : int
692
            id of the user to remove from the guild
693
        """
694
        await self._http.delete(f"guilds/{self.id}/members/{user_id}")
695
696
    async def ban(
697
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
698
        member_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
699
        reason: str = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
700
        delete_message_days: int = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
701
    ):
702
        """
703
        Parameters
704
        ----------
705
        member_id : :class:`int`
706
            ID of the guild member to ban.
707
        reason : Optional[:class:`str`]
708
            Reason for the kick.
709
        delete_message_days : Optional[:class:`int`]
710
            Number of days to delete messages for (0-7)
711
        """
712
        headers = {}
713
714
        if reason is not None:
715
            headers["X-Audit-Log-Reason"] = reason
716
717
        data = {}
718
719
        if delete_message_days is not None:
720
            data["delete_message_days"] = delete_message_days
721
722
        await self._http.put(
723
            f"/guilds/{self.id}/bans/{member_id}",
724
            data=data,
725
            headers=headers
726
        )
727
728
    async def kick(self, member_id: int, reason: Optional[str] = None):
729
        """|coro|
730
        Kicks a guild member.
731
        Parameters
732
        ----------
733
        member_id : :class:`int`
734
            ID of the guild member to kick.
735
        reason : Optional[:class:`str`]
736
            Reason for the kick.
737
        """
738
739
        headers = {}
740
741
        if reason is not None:
742
            headers["X-Audit-Log-Reason"] = reason
743
744
        await self._http.delete(
745
            f"/guilds/{self.id}/members/{member_id}",
746
            header=headers
747
        )
748
749
    async def get_roles(self) -> AsyncGenerator[Role, None]:
750
        """|coro|
751
        Fetches all the roles in the guild.
752
753
        Yields
754
        -------
755
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
756
            An async generator of Role objects.
757
        """
758
        data = await self._http.get(f"guilds/{self.id}/roles")
759
        for role_data in data:
760
            yield Role.from_dict(construct_client_dict(self._client, role_data))
761
762
    @overload
763
    async def create_role(
764
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
765
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
766
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
767
        name: Optional[str] = "new role",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
768
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
769
        color: Optional[int] = 0,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
770
        hoist: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
771
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
772
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
773
        mentionable: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
774
    ) -> Role:
775
        """|coro|
776
        Creates a new role for the guild.
777
        Requires the ``MANAGE_ROLES`` permission.
778
779
        Parameters
780
        ----------
781
        reason : Optional[:class:`str`]
782
            Reason for creating the role. |default| :data:`None`
783
        name : Optional[:class:`str`]
784
            name of the role |default| :data:`"new role"`
785
        permissions : Optional[:class:`str`]
786
            bitwise value of the enabled/disabled
787
            permissions, set to @everyone permissions
788
            by default |default| :data:`None`
789
        color : Optional[:class:`int`]
790
            RGB color value |default| :data:`0`
791
        hoist : Optional[:class:`bool`]
792
            whether the role should be displayed
793
            separately in the sidebar |default| :data:`False`
794
        icon : Optional[:class:`str`]
795
            the role's icon image (if the guild has
796
            the ``ROLE_ICONS`` feature) |default| :data:`None`
797
        unicode_emoji : Optional[:class:`str`]
798
            the role's unicode emoji as a standard emoji (if the guild
799
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
800
        mentionable : Optional[:class:`bool`]
801
            whether the role should be mentionable |default| :data:`False`
802
803
        Returns
804
        -------
805
        :class:`~pincer.objects.guild.role.Role`
806
            The new role object.
807
        """
808
        ...
809
810
    async def create_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
811
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
812
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
813
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
814
    ) -> Role:
815
        return Role.from_dict(
816
            construct_client_dict(
817
                self._client,
818
                await self._http.post(
819
                    f"guilds/{self.id}/roles",
820
                    data=kwargs,
821
                    headers=remove_none({"X-Audit-Log-Reason": reason})
822
                ),
823
            )
824
        )
825
826
    async def edit_role_position(
827
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
828
        id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
829
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
830
        position: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
831
    ) -> AsyncGenerator[Role, None]:
832
        """|coro|
833
        Edits the position of a role.
834
835
        Parameters
836
        ----------
837
        id : :class:`~pincer.utils.snowflake.Snowflake`
838
            The role ID
839
        reason : Optional[:class:`str`]
840
            Reason for editing the role position. |default| :data:`None`
841
        position : Optional[:class:`int`]
842
            Sorting position of the role |default| :data:`None`
843
844
        Yields
845
        -------
846
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
847
            An async generator of all of the guild's role objects.
848
        """
849
        data = await self._http.patch(
850
            f"guilds/{self.id}/roles",
851
            data={"id": id, "position": position},
852
            headers=remove_none({"X-Audit-Log-Reason": reason})
853
        )
854
        for role_data in data:
855
            yield Role.from_dict(construct_client_dict(self._client, role_data))
856
857
    @overload
858
    async def edit_role(
859
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
860
        id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
861
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
862
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
863
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
864
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
865
        color: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
866
        hoist: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
867
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
868
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
869
        mentionable: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
870
    ) -> Role:
871
        """|coro|
872
        Edits a role.
873
        Requires the ``MANAGE_ROLES`` permission.
874
875
        Parameters
876
        ----------
877
        id : :class:`~pincer.utils.snowflake.Snowflake`
878
            The role ID
879
        reason : Optional[:class:`str`]
880
            Reason for editing the role |default| :data:`None`
881
        name : Optional[:class:`str`]
882
            Name of the role |default| :data:`None`
883
        permissions : Optional[:class:`str`]
884
            Bitwise value of the enabled/disabled
885
            permissions |default| :data:`None`
886
        color : Optional[:class:`int`]
887
            RGB color value |default| :data:`None`
888
        hoist : Optional[:class:`bool`]
889
            Whether the role should be displayed
890
            separately in the sidebar |default| :data:`None`
891
        icon : Optional[:class:`str`]
892
            The role's icon image (if the guild has
893
            the ``ROLE_ICONS`` feature) |default| :data:`None`
894
        unicode_emoji : Optional[:class:`str`]
895
            The role's unicode emoji as a standard emoji (if the guild
896
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
897
        mentionable : Optional[:class:`bool`]
898
            Whether the role should be mentionable |default| :data:`None`
899
900
        Returns
901
        -------
902
        :class:`~pincer.objects.guild.role.Role`
903
            The edited role object.
904
        """
905
        ...
906
907
    async def edit_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
908
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
909
        id: Snowflake,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
910
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
911
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
912
    ) -> Role:
913
        return Role.from_dict(
914
            construct_client_dict(
915
                self._client,
916
                await self._http.patch(
917
                    f"guilds/{self.id}/roles/{id}",
918
                    data=kwargs,
919
                    headers=remove_none({"X-Audit-Log-Reason": reason})
920
                ),
921
            )
922
        )
923
924
    async def delete_role(self, id: Snowflake, reason: Optional[str] = None):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
925
        """|coro|
926
        Deletes a role.
927
        Requires the `MANAGE_ROLES` permission.
928
929
        Parameters
930
        ----------
931
        id : :class:`~pincer.utils.snowflake.Snowflake`
932
            The role ID
933
        reason : Optional[:class:`str`]
934
            The reason for deleting the role |default| :data:`None`
935
        """
936
        await self._http.delete(
937
            f"guilds/{self.id}/roles/{id}",
938
            headers=remove_none({"X-Audit-Log-Reason": reason})
939
        )
940
941
    async def get_bans(self) -> AsyncGenerator[Ban, None]:
942
        """|coro|
943
        Fetches all the bans in the guild.
944
945
        Yields
946
        -------
947
        AsyncGenerator[:class:`~pincer.objects.guild.ban.Ban`, :data:`None`]
948
            An async generator of Ban objects.
949
        """
950
        data = await self._http.get(f"guilds/{self.id}/bans")
951
        for ban_data in data:
952
            yield Ban.from_dict(construct_client_dict(self._client, ban_data))
953
954
    async def get_ban(self, id: Snowflake) -> Ban:
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
955
        """|coro|
956
        Fetches a ban from the guild.
957
958
        Parameters
959
        ----------
960
        id : :class:`~pincer.utils.snowflake.Snowflake`
961
            The user ID
962
963
        Returns
964
        -------
965
        :class:`~pincer.objects.guild.ban.Ban`
966
            The Ban object.
967
        """
968
        return Ban.from_dict(
969
            construct_client_dict(
970
                self._client,
971
                await self._http.get(f"guilds/{self.id}/bans/{id}"),
972
            )
973
        )
974
975
    async def unban(self, id: Snowflake, reason: Optional[str] = None):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
976
        """|coro|
977
        Unbans a user from the guild.
978
979
        Parameters
980
        ----------
981
        id : :class:`~pincer.utils.snowflake.Snowflake`
982
            The user ID
983
        reason : Optional[:class:`str`]
984
            The reason for unbanning the user |default| :data:`None`
985
        """
986
        await self._http.delete(
987
            f"guilds/{self.id}/bans/{id}",
988
            headers=remove_none({"X-Audit-Log-Reason": reason})
989
        )
990
991
    @overload
992
    async def edit(
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (20/15).
Loading history...
993
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
994
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
995
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
996
        region: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
997
        verification_level: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
998
        default_message_notifications: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
999
        explicit_content_filter: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1000
        afk_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1001
        afk_timeout: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1002
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1003
        owner_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1004
        splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1005
        discovery_splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1006
        banner: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1007
        system_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1008
        system_channel_flags: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1009
        rules_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1010
        public_updates_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1011
        preferred_locale: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1012
        features: Optional[List[GuildFeature]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1013
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1014
    ) -> Guild:
1015
        """|coro|
1016
        Modifies the guild
1017
1018
        Parameters
1019
        ----------
1020
        name : Optional[:class:`str`]
1021
            Guild name |default| :data:`None`
1022
        region : Optional[:class:`str`]
1023
            Guild voice region ID |default| :data:`None`
1024
        verification_level : Optional[:class:`int`]
1025
            Verification level |default| :data:`None`
1026
        default_message_notifications : Optional[:class:`int`]
1027
            Default message notification level |default| :data:`None`
1028
        explicit_content_filter : Optional[:class:`int`]
1029
            Explicit content filter level |default| :data:`None`
1030
        afk_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1031
            ID for AFK channel |default| :data:`None`
1032
        afk_timeout : Optional[:class:`int`]
1033
            AFK timeout in seconds |default| :data:`None`
1034
        icon : Optional[:class:`str`]
1035
            base64 1024x1024 png/jpeg/gif image for the guild icon
1036
            (can be animated gif when the server
1037
            has the `ANIMATED_ICON` feature) |default| :data:`None`
1038
        owner_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1039
            User ID to transfer guild ownership to (must be owner) |default| :data:`None`
1040
        splash : Optional[:class:`str`]
1041
            base64 16:9 png/jpeg image for the guild splash (when the
1042
            server has the `INVITE_SPLASH` feature) |default| :data:`None`
1043
        discovery_splash : Optional[:class:`str`]
1044
            base64 16:9 png/jpeg image for the guild discovery splash
1045
            (when the server has the `DISCOVERABLE` feature) |default| :data:`None`
1046
        banner : Optional[:class:`str`]
1047
            base64 16:9 png/jpeg image for the guild banner (when the
1048
            server has the `BANNER` feature) |default| :data:`None`
1049
        system_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1050
            The ID of the channel where guild notices such as welcome
1051
            messages and boost events are posted |default| :data:`None`
1052
        system_channel_flags : Optional[:class:`int`]
1053
            System channel flags |default| :data:`None`
1054
        rules_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1055
            The ID of the channel where Community guilds display rules
1056
            and/or guidelines |default| :data:`None`
1057
        public_updates_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1058
            The ID of the channel where admins and moderators of
1059
            Community guilds receive notices from Discord |default| :data:`None`
1060
        preferred_locale : Optional[:class:`str`]
1061
            The preferred locale of a Community guild used in server
1062
            discovery and notices from Discord; defaults to "en-US" |default| :data:`None`
1063
        features : Optional[List[:class:`GuildFeature`]]
1064
            Enabled guild features |default| :data:`None`
1065
        description : Optional[:class:`str`]
1066
            The description for the guild, if the guild is discoverable |default| :data:`None`
1067
1068
        Returns
1069
        -------
1070
        :class:`~pincer.objects.guild.Guild`
1071
            The modified guild object.
1072
        """
1073
        ...
1074
1075
    async def edit(self, **kwargs) -> Guild:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
1076
        g = await self._http.patch(f"guilds/{self.id}", data=kwargs)
1077
        return Guild.from_dict(construct_client_dict(self._client, g))
1078
1079
    async def preview(self) -> GuildPreview:
1080
        """|coro|
1081
        Previews the guild.
1082
1083
        Returns
1084
        -------
1085
        :class:`~pincer.objects.guild.guild.GuildPreview`
1086
            The guild preview object.
1087
        """
1088
        data = await self._http.get(f"guilds/{self.id}/preview")
1089
        return GuildPreview.from_dict(data)
1090
1091
    async def delete(self):
1092
        """|coro|
1093
        Deletes the guild. Returns `204 No Content` on success.
1094
        """
1095
        await self._http.delete(f"guilds/{self.id}")
1096
1097
    async def prune_count(
1098
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1099
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1100
        include_roles: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1101
    ) -> int:
1102
        """|coro|
1103
        Returns the number of members that
1104
        would be removed in a prune operation.
1105
        Requires the ``KICK_MEMBERS`` permission.
1106
1107
        Parameters
1108
        ----------
1109
        days : Optional[:class:`int`]
1110
            Number of days to count prune for (1-30) |default| :data:`7`
1111
        include_roles : Optional[:class:`str`]
1112
            Comma-delimited array of Snowflakes;
1113
            role(s) to include |default| :data:`None`
1114
1115
        Returns
1116
        -------
1117
        :class:`int`
1118
            The number of members that would be removed.
1119
        """
1120
        return await self._http.get(
1121
            f"guilds/{self.id}/prune?{days=}&{include_roles=!s}"
1122
        )["pruned"]
1123
1124
    async def prune(
1125
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1126
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1127
        compute_prune_days: Optional[bool] = True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1128
        include_roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1129
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1130
    ) -> int:
1131
        """|coro|
1132
        Prunes members from the guild. Requires the ``KICK_MEMBERS`` permission.
1133
1134
        Parameters
1135
1136
        Parameters
1137
        ----------
1138
        days : Optional[:class:`int`]
1139
            Number of days to prune (1-30) |default| :data:`7`
1140
        compute_prune_days : Optional[:class:`bool`]
1141
            Whether ``pruned`` is returned, discouraged for large guilds
1142
            |default| :data:`True`
1143
        include_roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1144
            role(s) to include |default| :data:`None`
1145
        reason : Optional[:class:`str`]
1146
            Reason for the prune |default| :data:`None`
1147
1148
        Returns
1149
        -------
1150
        :class:`int`
1151
            The number of members that were removed.
1152
        """
1153
        return await self._http.post(
1154
            f"guilds/{self.id}/prune",
1155
            data={
1156
                "days": days,
1157
                "compute_prune_days": compute_prune_days,
1158
                "include_roles": include_roles
1159
            },
1160
            headers=remove_none({"X-Audit-Log-Reason": reason})
1161
        )["pruned"]
1162
1163
    async def get_voice_regions(self) -> AsyncGenerator[VoiceRegion, None]:
1164
        """|coro|
1165
        Returns an async generator of voice regions.
1166
1167
        Yields
1168
        -------
1169
        AsyncGenerator[:class:`~pincer.objects.voice.VoiceRegion`, :data:`None`]
1170
            An async generator of voice regions.
1171
        """
1172
        data = await self._http.get(f"guilds/{self.id}/regions")
1173
        for voice_region_data in data:
1174
            yield VoiceRegion.from_dict(construct_client_dict(self._client, voice_region_data))
1175
1176
    async def get_invites(self) -> AsyncGenerator[Invite, None]:
1177
        """|coro|
1178
        Returns an async generator of invites for the guild.
1179
        Requires the ``MANAGE_GUILD`` permission.
1180
1181
        Yields
1182
        -------
1183
        AsyncGenerator[:class:`~pincer.objects.invite.Invite`, :data:`None`]
1184
            An async generator of invites.
1185
        """
1186
        data = await self._http.get(f"guilds/{self.id}/invites")
1187
        for invite_data in data:
1188
            yield Invite.from_dict(construct_client_dict(self._client, invite_data))
1189
1190
    async def get_integrations(self) -> AsyncGenerator[Integration, None]:
1191
        """|coro|
1192
        Returns an async generator of integrations for the guild.
1193
        Requires the ``MANAGE_GUILD`` permission.
1194
1195
        Yields
1196
        -------
1197
        AsyncGenerator[:class:`~pincer.objects.integration.Integration`, :data:`None`]
1198
            An async generator of integrations.
1199
        """
1200
        data = await self._http.get(f"guilds/{self.id}/integrations")
1201
        for integration_data in data:
1202
            yield Integration.from_dict(construct_client_dict(self._client, integration_data))
1203
1204
    async def delete_integration(
1205
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1206
        integration: Integration,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1207
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1208
    ):
1209
        """|coro|
1210
        Deletes an integration.
1211
        Requires the ``MANAGE_GUILD`` permission.
1212
1213
        Parameters
1214
        ----------
1215
        integration : :class:`~pincer.objects.integration.Integration`
1216
            The integration to delete.
1217
        reason : Optional[:class:`str`]
1218
            Reason for the deletion |default| :data:`None`
1219
        """
1220
        await self._http.delete(
1221
            f"guilds/{self.id}/integrations/{integration.id}",
1222
            headers=remove_none({"X-Audit-Log-Reason": reason})
1223
        )
1224
1225
    async def get_widget_settings(self) -> GuildWidget:
1226
        """|coro|
1227
        Returns the guild widget settings.
1228
        Requires the ``MANAGE_GUILD`` permission.
1229
1230
        Returns
1231
        -------
1232
        :class:`~pincer.objects.guild.widget.GuildWidget`
1233
            The guild widget settings.
1234
        """
1235
        return GuildWidget.from_dict(
1236
            construct_client_dict(
1237
                self._client,
1238
                await self._http.get(f"guilds/{self.id}/widget")
1239
            )
1240
        )
1241
1242
    async def modify_widget(
1243
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1244
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1245
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1246
    ) -> GuildWidget:
1247
        """|coro|
1248
        Modifies the guild widget for the guild.
1249
        Requires the ``MANAGE_GUILD`` permission.
1250
1251
        Parameters
1252
        ----------
1253
        reason : Optional[:class:`str`]
1254
            Reason for the modification |default| :data:`None`
1255
        \\*\\*kwargs
1256
            The widget settings to modify
1257
1258
        Returns
1259
        -------
1260
        :class:`~pincer.objects.guild.widget.GuildWidget`
1261
            The updated GuildWidget object
1262
        """
1263
        data = await self._http.patch(
1264
            f"guilds/{self.id}/widget",
1265
            data=kwargs,
1266
            headers=remove_none({"X-Audit-Log-Reason": reason})
1267
        )
1268
        return GuildWidget.from_dict(construct_client_dict(self._client, data))
1269
1270
    async def get_widget(self) -> Dict[str, JSONSerializable]:
1271
        """|coro|
1272
        Returns the widget for the guild
1273
        """
1274
        return await self._http.get(f"guilds/{self.id}/widget.json")
1275
1276
    @property
1277
    async def vanity_url(self) -> Invite:
1278
        """|coro|
1279
        Returns the Vanity URL for the guild.
1280
        Requires the ``MANAGE_GUILD`` permission.
1281
        ``code`` will be null if a vanity URL has not been set.
1282
1283
        Returns
1284
        -------
1285
        :class:`~pincer.objects.guild.invite.Invite`
1286
            The vanity url for the guild.
1287
        """
1288
        data = await self._http.get(f"guilds/{self.id}/vanity-url")
1289
        return Invite.from_dict(construct_client_dict(self._client, data))
1290
1291
    async def get_widget_image(self, style: Optional[str] = "shield") -> str:  # TODO Replace str with ImageURL object
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
Coding Style introduced by
This line is too long as per the coding-style (118/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
1292
        """|coro|
1293
        Returns a PNG image widget for the guild.
1294
        Requires no permissions or authentication.
1295
1296
        Widget Style Options
1297
        -------------------
1298
        * [``shield``](https://discord.com/api/guilds/81384788765712384/widget.png?style=shield)
1299
          shield style widget with Discord icon and guild members online count
1300
        * [``banner1``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner1)
1301
          large image with guild icon, name and online count.
1302
          "POWERED BY DISCORD" as the footer of the widget
1303
        * [``banner2``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner2)
1304
          smaller widget style with guild icon, name and online count.
1305
          Split on the right with Discord logo
1306
        * [``banner3``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner3)
1307
          large image with guild icon, name and online count.
1308
          In the footer, Discord logo on the
1309
          left and "Chat Now" on the right
1310
        * [``banner4``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner4)
1311
          large Discord logo at the top of the widget.
1312
          Guild icon, name and online count in the middle portion
1313
          of the widget and a "JOIN MY SERVER" button at the bottom
1314
1315
        Parameters
1316
        ----------
1317
        style : Optional[:class:`str`]
1318
            Style of the widget image returned |default| :data:`"shield"`
1319
1320
        Returns
1321
        -------
1322
        :class:`str`
1323
            A PNG image of the guild widget.
1324
        """
1325
        return await self._http.get(f"guilds/{self.id}/widget.png?{style=!s}")
1326
1327
    async def get_welcome_screen(self) -> WelcomeScreen:
1328
        """Returns the welcome screen for the guild.
1329
1330
        Returns
1331
        -------
1332
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1333
            The welcome screen for the guild.
1334
        """
1335
        data = await self._http.get(f"guilds/{self.id}/welcome-screen")
1336
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1337
1338
    async def modify_welcome_screen(
1339
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1340
        enabled: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1341
        welcome_channels: Optional[List[WelcomeScreenChannel]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1342
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1343
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1344
    ) -> WelcomeScreen:
1345
        """|coro|
1346
        Modifies the guild's Welcome Screen.
1347
        Requires the ``MANAGE_GUILD`` permission.
1348
1349
        Parameters
1350
        ----------
1351
        enabled : Optional[:class:`bool`]
1352
            Whether the welcome screen is enabled |default| :data:`None`
1353
        welcome_channels : Optional[List[:class:`~pincer.objects.guild.welcome_screen.WelcomeScreenChannel`]]
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
1354
            Channels linked in the welcome screen and
1355
            their display options |default| :data:`None`
1356
        description : Optional[:class:`str`]
1357
            The server description to show
1358
            in the welcome screen |default| :data:`None`
1359
        reason : Optional[:class:`str`]
1360
            Reason for the modification |default| :data:`None`
1361
1362
        Returns
1363
        -------
1364
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1365
            The updated WelcomeScreen object
1366
        """
1367
        data = await self._http.patch(
1368
            f"guilds/{self.id}/welcome-screen",
1369
            data={
1370
                "enabled": enabled,
1371
                "welcome_channels": welcome_channels,
1372
                "description": description
1373
            },
1374
            headers=remove_none({"X-Audit-Log-Reason": reason})
1375
        )
1376
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1377
1378
    async def modify_current_user_voice_state(
1379
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1380
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1381
        suppress: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1382
        request_to_speak_timestamp: Optional[Timestamp] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1383
    ):
1384
        """|coro|
1385
        Updates the current user's voice state.
1386
1387
        There are currently several caveats for this endpoint:
1388
        * ``channel_id`` must currently point to a stage channel
1389
        * current user must already have joined ``channel_id``
1390
        * You must have the ``MUTE_MEMBERS`` permission to
1391
          unsuppress yourself. You can always suppress yourself.
1392
        * You must have the ``REQUEST_TO_SPEAK`` permission to request
1393
          to speak. You can always clear your own request to speak.
1394
        * You are able to set ``request_to_speak_timestamp`` to any
1395
          present or future time.
1396
1397
        Parameters
1398
        ----------
1399
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1400
            The ID of the channel the user is currently in
1401
        suppress : Optional[:class:`bool`]
1402
            Toggles the user's suppress state |default| :data:`None`
1403
        request_to_speak_timestamp : Optional[:class:`~pincer.utils.timestamp.Timestamp`]
1404
            Sets the user's request to speak
1405
        """
1406
        await self._http.patch(
1407
            f"guilds/{self.id}/voice-states/@me",
1408
            data={
1409
                "channel_id": channel_id,
1410
                "suppress": suppress,
1411
                "request_to_speak_timestamp": request_to_speak_timestamp
1412
            }
1413
        )
1414
1415
    async def modify_user_voice_state(
1416
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1417
        user: User,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1418
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1419
        suppress: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1420
    ):
1421
        """|coro|
1422
        Updates another user's voice state.
1423
1424
        There are currently several caveats for this endpoint:
1425
        * ``channel_id`` must currently point to a stage channel
1426
        * User must already have joined ``channel_id``
1427
        * You must have the ``MUTE_MEMBERS`` permission.
1428
          (Since suppression is the only thing that is available currently.)
1429
        * When unsuppressed, non-bot users will have their
1430
          ``request_to_speak_timestamp`` set to the current time.
1431
          Bot users will not.
1432
        * When suppressed, the user will have their
1433
          ``request_to_speak_timestamp`` removed.
1434
1435
        Parameters
1436
        ----------
1437
        user : :class:`~pincer.objects.guild.member.Member`
1438
            The user to update
1439
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1440
            The ID of the channel the user is currently in
1441
        suppress : Optional[:class:`bool`]
1442
            Toggles the user's suppress state |default| :data:`None`
1443
        """
1444
        await self._http.patch(
1445
            f"guilds/{self.id}/voice-states/{user.id}",
1446
            data={
1447
                "channel_id": channel_id,
1448
                "suppress": suppress
1449
            }
1450
        )
1451
1452
    async def get_audit_log(self) -> AuditLog:
1453
        """|coro|
1454
        Returns an audit log object for the guild.
1455
        Requires the ``VIEW_AUDIT_LOG`` permission.
1456
1457
        Returns
1458
        -------
1459
        :class:`~pincer.objects.guild.audit_log.AuditLog`
1460
            The audit log object for the guild.
1461
        """
1462
        return AuditLog.from_dict(
1463
            construct_client_dict(
1464
                self._client,
1465
                await self._http.get(f"guilds/{self.id}/audit-logs")
1466
            )
1467
        )
1468
1469
    async def get_emojis(self) -> AsyncGenerator[Emoji, None]:
1470
        """|coro|
1471
        Returns an async generator of the emojis in the guild.
1472
1473
        Yields
1474
        ------
1475
        :class:`~pincer.objects.guild.emoji.Emoji`
1476
            The emoji object.
1477
        """
1478
        data = await self._http.get(f"guilds/{self.id}/emojis")
1479
        for emoji_data in data:
1480
            yield Emoji.from_dict(
1481
                construct_client_dict(self._client, emoji_data)
1482
            )
1483
1484
    async def get_emoji(self, id: Snowflake) -> Emoji:
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
1485
        """|coro|
1486
        Returns an emoji object for the given ID.
1487
1488
        Parameters
1489
        ----------
1490
        id : :class:`~pincer.utils.snowflake.Snowflake`
1491
            The ID of the emoji
1492
1493
        Returns
1494
        -------
1495
        :class:`~pincer.objects.guild.emoji.Emoji`
1496
            The emoji object.
1497
        """
1498
        return Emoji.from_dict(
1499
            construct_client_dict(
1500
                self._client,
1501
                await self._http.get(f"guilds/{self.id}/emojis/{id}")
1502
            )
1503
        )
1504
1505
    async def create_emoji(
1506
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1507
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1508
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1509
        image: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1510
        roles: List[Snowflake],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1511
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1512
    ) -> Emoji:
1513
        """|coro|
1514
        Creates a new emoji for the guild.
1515
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1516
1517
        Emojis and animated emojis have a maximum file size of 256kb.
1518
        Attempting to upload an emoji larger than this limit will fail.
1519
1520
        Parameters
1521
        ----------
1522
        name : :class:`str`
1523
            Name of the emoji
1524
        image : :class:`str`
1525
            The 128x128 emoji image data
1526
        roles : List[:class:`~pincer.utils.snowflake.Snowflake`]
1527
            Roles allowed to use this emoji
1528
        reason : Optional[:class:`str`]
1529
            The reason for creating the emoji |default| :data:`None`
1530
1531
        Returns
1532
        -------
1533
        :class:`~pincer.objects.guild.emoji.Emoji`
1534
            The newly created emoji object.
1535
        """
1536
        data = await self._http.post(
1537
            f"guilds/{self.id}/emojis",
1538
            data={
1539
                "name": name,
1540
                "image": image,
1541
                "roles": roles
1542
            },
1543
            headers=remove_none({"X-Audit-Log-Reason": reason})
1544
        )
1545
        return Emoji.from_dict(
1546
            construct_client_dict(self._client, data)
1547
        )
1548
1549
    async def edit_emoji(
1550
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1551
        id: Snowflake,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1552
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1553
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1554
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1555
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1556
    ) -> Emoji:
1557
        """|coro|
1558
        Modifies the given emoji.
1559
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1560
1561
        Parameters
1562
        ----------
1563
        id : :class:`~pincer.utils.snowflake.Snowflake`
1564
            The ID of the emoji
1565
        name : Optional[:class:`str`]
1566
            Name of the emoji |default| :data:`None`
1567
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1568
            Roles allowed to use this emoji |default| :data:`None`
1569
        reason : Optional[:class:`str`]
1570
            The reason for editing the emoji |default| :data:`None`
1571
1572
        Returns
1573
        -------
1574
        :class:`~pincer.objects.guild.emoji.Emoji`
1575
            The modified emoji object.
1576
        """
1577
        data = await self._http.patch(
1578
            f"guilds/{self.id}/emojis/{id}",
1579
            data={
1580
                "name": name,
1581
                "roles": roles
1582
            },
1583
            headers=remove_none({"X-Audit-Log-Reason": reason})
1584
        )
1585
        return Emoji.from_dict(
1586
            construct_client_dict(self._client, data)
1587
        )
1588
1589
    async def delete_emoji(
1590
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1591
        id: Snowflake,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1592
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1593
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1594
    ):
1595
        """|coro|
1596
        Deletes the given emoji.
1597
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1598
1599
        Parameters
1600
        ----------
1601
        id : :class:`~pincer.utils.snowflake.Snowflake`
1602
            The ID of the emoji
1603
        reason : Optional[:class:`str`]
1604
            The reason for deleting the emoji |default| :data:`None`
1605
        """
1606
        await self._http.delete(
1607
            f"guilds/{self.id}/emojis/{id}",
1608
            headers=remove_none({"X-Audit-Log-Reason": reason})
1609
        )
1610
1611
    async def get_templates(self) -> AsyncGenerator[GuildTemplate, None]:
1612
        """|coro|
1613
        Returns an async generator of the guild templates.
1614
1615
        Yields
1616
        -------
1617
        AsyncGenerator[:class:`~pincer.objects.guild.template.GuildTemplate`, :data:`None`]
1618
            The guild template object.
1619
        """
1620
        data = await self._http.get(f"guilds/{self.id}/templates")
1621
        for template_data in data:
1622
            yield GuildTemplate.from_dict(
1623
                construct_client_dict(self._client, template_data)
1624
            )
1625
1626
    async def create_template(
1627
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1628
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1629
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1630
    ) -> GuildTemplate:
1631
        """|coro|
1632
        Creates a new template for the guild.
1633
        Requires the ``MANAGE_GUILD`` permission.
1634
1635
        Parameters
1636
        ----------
1637
        name : :class:`str`
1638
            Name of the template (1-100 characters)
1639
        description : Optional[:class:`str`]
1640
            Description of the template
1641
            (0-120 characters) |default| :data:`None`
1642
        Returns
1643
        -------
1644
        :class:`~pincer.objects.guild.template.GuildTemplate`
1645
            The newly created template object.
1646
        """
1647
        data = await self._http.post(
1648
            f"guilds/{self.id}/templates",
1649
            data={
1650
                "name": name,
1651
                "description": description
1652
            }
1653
        )
1654
        return GuildTemplate.from_dict(
1655
            construct_client_dict(self._client, data)
1656
        )
1657
1658
    async def sync_template(
1659
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1660
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1661
    ) -> GuildTemplate:
1662
        """|coro|
1663
        Syncs the given template.
1664
        Requires the ``MANAGE_GUILD`` permission.
1665
1666
        Parameters
1667
        ----------
1668
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1669
            The template to sync
1670
1671
        Returns
1672
        -------
1673
        :class:`~pincer.objects.guild.template.GuildTemplate`
1674
            The synced template object.
1675
        """
1676
        data = await self._http.put(
1677
            f"guilds/{self.id}/templates/{template.code}"
1678
        )
1679
        return GuildTemplate.from_dict(
1680
            construct_client_dict(self._client, data)
1681
        )
1682
1683
    async def edit_template(
1684
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1685
        template: GuildTemplate,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1686
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1687
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1688
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1689
    ) -> GuildTemplate:
1690
        """|coro|
1691
        Modifies the template's metadata.
1692
        Requires the ``MANAGE_GUILD`` permission.
1693
1694
        Parameters
1695
        ----------
1696
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1697
            The template to edit
1698
        name : Optional[:class:`str`]
1699
            Name of the template (1-100 characters)
1700
            |default| :data:`None`
1701
        description : Optional[:class:`str`]
1702
            Description of the template (0-120 characters)
1703
            |default| :data:`None`
1704
1705
        Returns
1706
        -------
1707
        :class:`~pincer.objects.guild.template.GuildTemplate`
1708
            The edited template object.
1709
        """
1710
        data = await self._http.patch(
1711
            f"guilds/{self.id}/templates/{template.code}",
1712
            data={
1713
                "name": name,
1714
                "description": description
1715
            }
1716
        )
1717
        return GuildTemplate.from_dict(
1718
            construct_client_dict(self._client, data)
1719
        )
1720
1721
    async def delete_template(
1722
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1723
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1724
    ) -> GuildTemplate:
1725
        """|coro|
1726
        Deletes the given template.
1727
        Requires the ``MANAGE_GUILD`` permission.
1728
1729
        Parameters
1730
        ----------
1731
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1732
            The template to delete
1733
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1734
        Returns
1735
        -------
1736
        :class:`~pincer.objects.guild.template.GuildTemplate`
1737
            The deleted template object.
1738
        """
1739
        data = await self._http.delete(
1740
            f"guilds/{self.id}/templates/{template.code}"
1741
        )
1742
        return GuildTemplate.from_dict(
1743
            construct_client_dict(self._client, data)
1744
        )
1745
1746
    @classmethod
1747
    def from_dict(cls, data) -> Guild:
1748
        """
1749
        Parameters
1750
        ----------
1751
        data : :class:`Dict`
1752
            Guild data received from the discord API.
1753
        Returns
1754
        -------
1755
        :class:`~pincer.objects.guild.guild.Guild`
1756
            The new guild object.
1757
        Raises
1758
        :class:`~pincer.exceptions.UnavailableGuildError`
1759
            The guild is unavailable due to a discord outage.
1760
        """
1761
        if data.get("unavailable", False):
1762
            raise UnavailableGuildError(
1763
                f"Guild \"{data['id']}\" is unavailable due to a discord"
1764
                " outage."
1765
            )
1766
1767
        return super().from_dict(data)
1768
1769
1770
@dataclass
1771
class UnavailableGuild(APIObject):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
1772
    id: Snowflake
1773
    unavailable: bool = True
1774