Completed
Push — main ( c248a1...493d97 )
by
unknown
19s queued 13s
created

pincer.objects.guild.guild.Guild.create_template()   A

Complexity

Conditions 1

Size

Total Lines 30
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 30
rs 9.85
c 0
b 0
f 0
cc 1
nop 3
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 (1562/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, Union
17
18
    from .audit_log import AuditLog
19
    from .ban import Ban
20
    from .channel import Channel
21
    from .invite import Invite
22
    from .member import GuildMember
23
    from .features import GuildFeature
24
    from .role import Role
25
    from .stage import StageInstance
26
    from .template import GuildTemplate
27
    from .welcome_screen import WelcomeScreen, WelcomeScreenChannel
28
    from .widget import GuildWidget
29
    from ..user.user import User
30
    from ..user.integration import Integration
31
    from ..voice.region import VoiceRegion
32
    from ..events.presence import PresenceUpdateEvent
33
    from ..message.emoji import Emoji
34
    from ..message.sticker import Sticker
35
    from ..user.voice_state import VoiceState
36
    from ...client import Client
37
    from ...utils.timestamp import Timestamp
38
    from ...utils.types import APINullable, JSONSerializable
39
    from ...utils.snowflake import Snowflake
40
41
42
class PremiumTier(IntEnum):
43
    """Represents the boost tier of a guild.
44
    Attributes
45
    ----------
46
    NONE:
47
        Guild has not unlocked any Server Boost perks.
48
    TIER_1:
49
        Guild has unlocked Server Boost level 1 perks.
50
    TIER_2:
51
        Guild has unlocked Server Boost level 2 perks.
52
    TIER_3:
53
        Guild has unlocked Server Boost level 3 perks.
54
    """
55
56
    NONE = 0
57
    TIER_1 = 1
58
    TIER_2 = 2
59
    TIER_3 = 3
60
61
62
class GuildNSFWLevel(IntEnum):
63
    """Represents the NSFW level of a guild.
64
    Attributes
65
    ----------
66
    DEFAULT:
67
        Default NSFW level.
68
    EXPLICIT:
69
        Explicit NSFW level.
70
    SAFE:
71
        SAFE NSFW level.
72
    AGE_RESTRICTED:
73
        Age restricted NSFW level.
74
    """
75
76
    DEFAULT = 0
77
    EXPLICIT = 1
78
    SAFE = 2
79
    AGE_RESTRICTED = 3
80
81
82
class ExplicitContentFilterLevel(IntEnum):
83
    """Represents the filter content level of a guild.
84
    Attributes
85
    ----------
86
    DISABLED:
87
        Media content will not be scanned.
88
    MEMBERS_WITHOUT_ROLES:
89
        Media content sent by members without roles will be scanned.
90
    ALL_MEMBERS:
91
        Media content sent by all members will be scanned.
92
    """
93
94
    DISABLED = 0
95
    MEMBERS_WITHOUT_ROLES = 1
96
    ALL_MEMBERS = 2
97
98
99
class MFALevel(IntEnum):
100
    """Represents the multi factor authentication level of a guild.
101
    Attributes
102
    ----------
103
    NONE:
104
        Guild has no MFA/2FA requirement for moderation actions.
105
    ELEVATED:
106
        Guild has a 2FA requirement for moderation actions
107
    """
108
109
    NONE = 0
110
    ELEVATED = 1
111
112
113
class VerificationLevel(IntEnum):
114
    """Represents the verification level of a guild.
115
    Attributes
116
    ----------
117
    NONE:
118
        Unrestricted.
119
    LOW:
120
        Must have verified email on account.
121
    MEDIUM:
122
        Must be registered on Discord for longer than 5 minutes.
123
    HIGH:
124
        Must be a member of the server for longer than 10 minutes.
125
    VERY_HIGH:
126
        Must have a verified phone number.
127
    """
128
129
    NONE = 0
130
    LOW = 1
131
    MEDIUM = 2
132
    HIGH = 3
133
    VERY_HIGH = 4
134
135
136
class DefaultMessageNotificationLevel(IntEnum):
137
    """Represents the default message notification level of a guild.
138
    Attributes
139
    ----------
140
    ALL_MESSAGES:
141
        Members will receive notifications for all messages by default.
142
    ONLY_MENTIONS:
143
        Members will receive notifications only for messages that @mention them by default.
144
    """
145
146
    # noqa: E501
147
    ALL_MESSAGES = 0
148
    ONLY_MENTIONS = 1
149
150
151
class SystemChannelFlags(IntEnum):
152
    """Represents the system channel flags of a guild.
153
    Attributes
154
    ----------
155
    SUPPRESS_JOIN_NOTIFICATIONS:
156
        Suppress member join notifications.
157
    SUPPRESS_PREMIUM_SUBSCRIPTIONS:
158
        Suppress server boost notifications.
159
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS:
160
        Suppress server setup tips.
161
    SUPPRESS_JOIN_NOTIFICATION_REPLIES:
162
        Hide member join sticker reply buttons
163
    """
164
165
    SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0
166
    SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
167
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS = 1 << 2
168
    SUPPRESS_JOIN_NOTIFICATION_REPLIES = 1 << 3
169
170
171
@dataclass
172
class GuildPreview(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (10/7)
Loading history...
173
    """Represents a guild preview.
174
    Attributes
175
    ----------
176
    id: :class:`Snowflake`
177
        The guild ID.
178
    name: :class:`str`
179
        The guild name.
180
    icon: :class:`str`
181
        The guild icon hash.
182
    splash: :class:`str`
183
        The guild splash hash.
184
    discovery_splash: :class:`str`
185
        The guild discovery splash hash.
186
    emojis: :class:`List[Emoji]`
187
        The guild emojis.
188
    features: :class:`List[GuildFeature]`
189
        The guild features.
190
    approximate_member_count: :class:`int`
191
        The approximate member count.
192
    approximate_presence_count: :class:`int`
193
        The approximate number of online members in this guild
194
    description: :class:`str`
195
        The guild description.
196
    """
197
198
    id: Snowflake
199
    name: str
200
    emojis: List[Emoji]
201
    features: List[GuildFeature]
202
    approximate_member_count: int
203
    approximate_presence_count: int
204
205
    icon: APINullable[str] = MISSING
206
    splash: APINullable[str] = MISSING
207
    discovery_splash: APINullable[str] = MISSING
208
    description: APINullable[str] = MISSING
209
210
211
@dataclass
212
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 (43/20)
Loading history...
213
    """Represents a Discord guild/server in which your client resides.
214
    Attributes
215
    ----------
216
    afk_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
217
        Id of afk channel
218
    afk_timeout: :class:`int`
219
        Afk timeout in seconds
220
    application_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
221
        Application id of the guild creator if it is bot-created
222
    banner: Optional[:class:`str`]
223
        Banner hash
224
    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...
225
        Default message notifications level
226
    description: Optional[:class:`str`]
227
        The description of a Community guild
228
    discovery_splash: Optional[:class:`str`]
229
        Discovery splash hash;
230
        only present for guilds with the "DISCOVERABLE" feature
231
    emojis: List[:class:`~pincer.objects.message.emoji.Emoji`]
232
        Custom guild emojis
233
    explicit_content_filter: :class:`~pincer.objects.guild.guild.ExplicitContentFilterLevel`
234
        Explicit content filter level
235
    features: List[:class:`~pincer.objects.guild.features.GuildFeature`]
236
        Enabled guild features
237
    id: :class:`~pincer.utils.snowflake.Snowflake`
238
        Guild id
239
    icon: Optional[:class:`str`]
240
        Icon hash
241
    mfa_level: :class:`~pincer.objects.guild.guild.MFALevel`
242
        Required MFA level for the guild
243
    name: :class:`str`
244
        Guild name (2-100 characters, excluding trailing and leading
245
        whitespace)
246
    nsfw_level: :class:`~pincer.objects.guild.guild.NSFWLevel`
247
        Guild NSFW level
248
    owner_id: :class:`~pincer.utils.snowflake.Snowflake`
249
        Id of owner
250
    preferred_locale: :class:`str`
251
        The preferred locale of a Community guild;
252
        used in server discovery and notices from Discord;
253
        defaults to "en-US"
254
    premium_tier: :class:`~pincer.objects.guild.guild.PremiumTier`
255
        Premium tier (Server Boost level)
256
    public_updates_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
257
        The id of the channel where admins
258
        and moderators of Community guilds receive notices from Discord
259
    roles: List[:class:`~pincer.objects.guild.role.Role`]
260
        Roles in the guild
261
    rules_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
262
        The id of the channel where Community guilds can display rules
263
        and/or guidelines
264
    splash: Optional[:class:`str`]
265
        Splash hash
266
    system_channel_flags: :class:`~pincer.objects.guild.guild.SystemChannelFlags`
267
        System channel flags
268
    system_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
269
        The id of the channel where guild notices
270
        such as welcome messages and boost events are posted
271
    vanity_url_code: Optional[:class:`str`]
272
        The vanity url code for the guild
273
    verification_level: :class:`~pincer.objects.guild.guild.VerificationLevel`
274
        Verification level required for the guild
275
    approximate_member_count: APINullable[:class:`int`]
276
        Approximate number of members in this guild, returned from the
277
        `GET /guilds/<id>` endpoint when with_counts is true
278
    approximate_presence_count: APINullable[:class:`int`]
279
        Approximate number of non-offline members in this guild,
280
        returned from the `GET /guilds/<id>`
281
        endpoint when with_counts is true
282
    channels: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
283
        Channels in the guild
284
    icon_hash: APINullable[Optional[:class:`str`]]
285
        Icon hash, returned when in the template object
286
    joined_at: APINullable[:class:`~pincer.utils.timestamp.Timestamp`]
287
        When this guild was joined at
288
    large: APINullable[:class:`bool`]
289
        True if this is considered a large guild
290
    max_members: APINullable[:class:`int`]
291
        The maximum number of members for the guild
292
    max_presences: APINullable[Optional[:class:`int`]]
293
        The maximum number of presences for the guild
294
        (null is always returned, apart from the largest of guilds)
295
    max_video_channel_users: APINullable[:class:`int`]
296
        The maximum amount of users in a video channel
297
    members: APINullable[List[:class:`~pincer.objects.guild.member.GuildMember`]]
298
        Users in the guild
299
    member_count: APINullable[:class:`bool`]
300
        Total number of members in this guild
301
    nsfw: APINullable[:class:`bool`]
302
        Boolean if the server is NSFW
303
    owner: APINullable[:class:`bool`]
304
        True if the user is the owner of the guild
305
    permissions: APINullable[:class:`str`]
306
        Total permissions for the user in the guild
307
        (excludes overwrites)
308
    premium_subscription_count: APINullable[:class:`int`]
309
        The number of boosts this guild currently has
310
    presences: APINullable[List[:class:`~pincer.objects.events.presence.PresenceUpdateEvent`]]
311
        Presences of the members in the guild,
312
        will only include non-offline members if the size is greater
313
        than large threshold
314
    stage_instances: APINullable[List[:class:`~pincer.objects.guild.stage.StageInstance`]]
315
        Stage instances in the guild
316
    stickers: Optional[List[:class:`~pincer.objects.message.sticker.Sticker`]]
317
        Custom guild stickers
318
    region: APINullable[Optional[:class:`str`]]
319
        Voice region id for the guild (deprecated)
320
    threads: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
321
        All active threads in the guild that current user
322
        has permission to view
323
    unavailable: APINullable[:class:`bool`]
324
        True if this guild is unavailable due to an outage
325
    voice_states: APINullable[List[:class:`~pincer.objects.user.voice_state.VoiceState`]]
326
        States of members currently in voice channels;
327
        lacks the guild_id key
328
    widget_enabled: APINullable[:class:`bool`]
329
        True if the server widget is enabled
330
    widget_channel_id: APINullable[Optional[:class:`~pincer.utils.snowflake.Snowflake`]]
331
        The channel id that the widget will generate an invite to,
332
        or null if set to no invite
333
    welcome_screen: APINullable[:class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`]
334
        The welcome screen of a Community guild, shown to new members,
335
        returned in an Invite's guild object
336
    """
337
338
    # noqa: E501
339
    afk_timeout: int
340
    default_message_notifications: DefaultMessageNotificationLevel
341
    emojis: List[Emoji]
342
    explicit_content_filter: ExplicitContentFilterLevel
343
    features: List[GuildFeature]
344
    id: Snowflake
345
    mfa_level: MFALevel
346
    name: str
347
    nsfw_level: GuildNSFWLevel
348
    owner_id: Snowflake
349
    preferred_locale: str
350
    premium_tier: PremiumTier
351
    roles: List[Role]
352
    system_channel_flags: SystemChannelFlags
353
    verification_level: VerificationLevel
354
355
    guild_scheduled_events: APINullable[List] = MISSING
356
    lazy: APINullable[bool] = MISSING
357
    premium_progress_bar_enabled: APINullable[bool] = MISSING
358
    guild_hashes: APINullable[Dict] = MISSING
359
    afk_channel_id: APINullable[Snowflake] = MISSING
360
    application_id: APINullable[Snowflake] = MISSING
361
    embedded_activities: APINullable[List] = MISSING
362
    banner: APINullable[str] = MISSING
363
    description: APINullable[str] = MISSING
364
    discovery_splash: APINullable[str] = MISSING
365
    icon: APINullable[str] = MISSING
366
    public_updates_channel_id: APINullable[Snowflake] = MISSING
367
    rules_channel_id: APINullable[Snowflake] = MISSING
368
    splash: APINullable[str] = MISSING
369
    system_channel_id: APINullable[Snowflake] = MISSING
370
    vanity_url_code: APINullable[str] = MISSING
371
372
    application_command_counts: APINullable[Dict] = MISSING
373
    application_command_count: APINullable[int] = MISSING
374
    approximate_member_count: APINullable[int] = MISSING
375
    approximate_presence_count: APINullable[int] = MISSING
376
    channels: APINullable[List[Channel]] = field(default_factory=list)
377
    # 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...
378
    hub_type: APINullable[Any] = MISSING
379
    icon_hash: APINullable[Optional[str]] = MISSING
380
    joined_at: APINullable[Timestamp] = MISSING
381
    large: APINullable[bool] = MISSING
382
    max_members: APINullable[int] = MISSING
383
    max_presences: APINullable[Optional[int]] = MISSING
384
    max_video_channel_users: APINullable[int] = MISSING
385
    members: APINullable[List[GuildMember]] = MISSING
386
    member_count: APINullable[bool] = MISSING
387
    nsfw: APINullable[bool] = MISSING
388
    # Note: This is missing from discord's docs but in the api
389
    owner: APINullable[bool] = MISSING
390
    permissions: APINullable[str] = MISSING
391
    premium_subscription_count: APINullable[int] = MISSING
392
    presences: APINullable[List[PresenceUpdateEvent]] = MISSING
393
    stage_instances: APINullable[List[StageInstance]] = MISSING
394
    stickers: APINullable[List[Sticker]] = MISSING
395
    region: APINullable[Optional[str]] = MISSING
396
    threads: APINullable[List[Channel]] = MISSING
397
    # Guilds are considered available unless otherwise specified
398
    unavailable: APINullable[bool] = False
399
    voice_states: APINullable[List[VoiceState]] = MISSING
400
    widget_enabled: APINullable[bool] = MISSING
401
    widget_channel_id: APINullable[Optional[Snowflake]] = MISSING
402
    welcome_screen: APINullable[WelcomeScreen] = MISSING
403
404
    @classmethod
405
    async def from_id(cls, client: Client, _id: Union[int, Snowflake]) -> Guild:
406
        """
407
        Parameters
408
        ----------
409
        client : `~pincer.Client`
410
            Client object to use the http gateway from.
411
        _id : :class: `pincer.utils.snowflake.Snowflake`
412
            Guild ID.
413
        Returns
414
        -------
415
        :class: `~pincer.objects.guild.guild.Guild`
416
            The new guild object.
417
        """
418
        data = await client.http.get(f"/guilds/{_id}")
419
        channel_data = await client.http.get(f"/guilds/{_id}/channels")
420
421
        data["channels"]: List[Channel] = [
422
            Channel.from_dict({**i, "_client": client, "_http": client.http})
423
            for i in (channel_data or [])
424
        ]
425
426
        return Guild.from_dict(construct_client_dict(client, data))
427
428
    async def get_member(self, _id: int) -> GuildMember:
429
        """|coro|
430
        Fetches a GuildMember from its identifier
431
432
        Parameters
433
        ----------
434
        _id: int
435
            The id of the guild member which should be fetched from the Discord
436
            gateway.
437
        Returns
438
        -------
439
        :class:`~pincer.objects.guild.member.GuildMember`
440
            A GuildMember object.
441
        """
442
        return await GuildMember.from_id(self._client, self.id, _id)
443
444
    @overload
445
    async def modify_member(
446
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
447
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
448
        _id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
449
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
450
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
451
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
452
        deaf: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
453
        channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
454
    ) -> GuildMember:
455
        """|coro|
456
        Modifies a member in the guild from its identifier and based on the
457
        keyword arguments provided.
458
        Parameters
459
        ----------
460
        _id : int
461
            Id of the member to modify
462
        nick : Optional[:class:`str`]
463
            New nickname for the member |default| :data:`None`
464
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake]]
465
            New roles for the member |default| :data:`None`
466
        mute : Optional[:class:`bool`]
467
            Whether the member is muted |default| :data:`None`
468
        deaf : Optional[:class:`bool`]
469
            Whether the member is deafened |default| :data:`None`
470
        channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake]
471
            Voice channel id to move to |default| :data:`None`
472
        Returns
473
        -------
474
        :class:`~pincer.objects.guild.member.GuildMember`
475
            The new member object.
476
        """
477
        ...
478
479
    async def modify_member(self, _id: int, **kwargs) -> GuildMember:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
480
        data = await self._http.patch(
481
            f"guilds/{self.id}/members/{_id}", data=kwargs
482
        )
483
        return GuildMember.from_dict(construct_client_dict(self._client, data))
484
485
    async def ban(
486
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
487
        member_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
488
        reason: str = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
489
        delete_message_days: int = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
490
    ):
491
        """
492
        Parameters
493
        ----------
494
        member_id : :class:`int`
495
            ID of the guild member to ban.
496
        reason : Optional[:class:`str`]
497
            Reason for the kick.
498
        delete_message_days : Optional[:class:`int`]
499
            Number of days to delete messages for (0-7)
500
        """
501
        headers = {}
502
503
        if reason is not None:
504
            headers["X-Audit-Log-Reason"] = reason
505
506
        data = {}
507
508
        if delete_message_days is not None:
509
            data["delete_message_days"] = delete_message_days
510
511
        await self._http.put(
512
            f"/guilds/{self.id}/bans/{member_id}",
513
            data=data,
514
            headers=headers
515
        )
516
517
    async def kick(self, member_id: int, reason: Optional[str] = None):
518
        """|coro|
519
        Kicks a guild member.
520
        Parameters
521
        ----------
522
        member_id : :class:`int`
523
            ID of the guild member to kick.
524
        reason : Optional[:class:`str`]
525
            Reason for the kick.
526
        """
527
528
        headers = {}
529
530
        if reason is not None:
531
            headers["X-Audit-Log-Reason"] = reason
532
533
        await self._http.delete(
534
            f"/guilds/{self.id}/members/{member_id}",
535
            header=headers
536
        )
537
538
    async def get_roles(self) -> AsyncGenerator[Role, None]:
539
        """|coro|
540
        Fetches all the roles in the guild.
541
542
        Yields
543
        -------
544
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
545
            An async generator of Role objects.
546
        """
547
        data = await self._http.get(f"guilds/{self.id}/roles")
548
        for role_data in data:
549
            yield Role.from_dict(construct_client_dict(self._client, role_data))
550
551
    @overload
552
    async def create_role(
553
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
554
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
555
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
556
        name: Optional[str] = "new role",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
557
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
558
        color: Optional[int] = 0,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
559
        hoist: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
560
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
561
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
562
        mentionable: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
563
    ) -> Role:
564
        """|coro|
565
        Creates a new role for the guild.
566
        Requires the ``MANAGE_ROLES`` permission.
567
568
        Parameters
569
        ----------
570
        reason : Optional[:class:`str`]
571
            Reason for creating the role. |default| :data:`None`
572
        name : Optional[:class:`str`]
573
            name of the role |default| :data:`"new role"`
574
        permissions : Optional[:class:`str`]
575
            bitwise value of the enabled/disabled
576
            permissions, set to @everyone permissions
577
            by default |default| :data:`None`
578
        color : Optional[:class:`int`]
579
            RGB color value |default| :data:`0`
580
        hoist : Optional[:class:`bool`]
581
            whether the role should be displayed
582
            separately in the sidebar |default| :data:`False`
583
        icon : Optional[:class:`str`]
584
            the role's icon image (if the guild has
585
            the ``ROLE_ICONS`` feature) |default| :data:`None`
586
        unicode_emoji : Optional[:class:`str`]
587
            the role's unicode emoji as a standard emoji (if the guild
588
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
589
        mentionable : Optional[:class:`bool`]
590
            whether the role should be mentionable |default| :data:`False`
591
592
        Returns
593
        -------
594
        :class:`~pincer.objects.guild.role.Role`
595
            The new role object.
596
        """
597
        ...
598
599
    async def create_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
600
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
601
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
602
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
603
    ) -> Role:
604
        return Role.from_dict(
605
            construct_client_dict(
606
                self._client,
607
                await self._http.post(
608
                    f"guilds/{self.id}/roles",
609
                    data=kwargs,
610
                    headers=remove_none({"X-Audit-Log-Reason": reason})
611
                ),
612
            )
613
        )
614
615
    async def edit_role_position(
616
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
617
        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...
618
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
619
        position: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
620
    ) -> AsyncGenerator[Role, None]:
621
        """|coro|
622
        Edits the position of a role.
623
624
        Parameters
625
        ----------
626
        id : :class:`~pincer.utils.snowflake.Snowflake`
627
            The role ID
628
        reason : Optional[:class:`str`]
629
            Reason for editing the role position. |default| :data:`None`
630
        position : Optional[:class:`int`]
631
            Sorting position of the role |default| :data:`None`
632
633
        Yields
634
        -------
635
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
636
            An async generator of all of the guild's role objects.
637
        """
638
        data = await self._http.patch(
639
            f"guilds/{self.id}/roles",
640
            data={"id": id, "position": position},
641
            headers=remove_none({"X-Audit-Log-Reason": reason})
642
        )
643
        for role_data in data:
644
            yield Role.from_dict(construct_client_dict(self._client, role_data))
645
646
    @overload
647
    async def edit_role(
648
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
649
        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...
650
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
651
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
652
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
653
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
654
        color: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
655
        hoist: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
656
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
657
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
658
        mentionable: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
659
    ) -> Role:
660
        """|coro|
661
        Edits a role.
662
        Requires the ``MANAGE_ROLES`` permission.
663
664
        Parameters
665
        ----------
666
        id : :class:`~pincer.utils.snowflake.Snowflake`
667
            The role ID
668
        reason : Optional[:class:`str`]
669
            Reason for editing the role |default| :data:`None`
670
        name : Optional[:class:`str`]
671
            Name of the role |default| :data:`None`
672
        permissions : Optional[:class:`str`]
673
            Bitwise value of the enabled/disabled
674
            permissions |default| :data:`None`
675
        color : Optional[:class:`int`]
676
            RGB color value |default| :data:`None`
677
        hoist : Optional[:class:`bool`]
678
            Whether the role should be displayed
679
            separately in the sidebar |default| :data:`None`
680
        icon : Optional[:class:`str`]
681
            The role's icon image (if the guild has
682
            the ``ROLE_ICONS`` feature) |default| :data:`None`
683
        unicode_emoji : Optional[:class:`str`]
684
            The role's unicode emoji as a standard emoji (if the guild
685
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
686
        mentionable : Optional[:class:`bool`]
687
            Whether the role should be mentionable |default| :data:`None`
688
689
        Returns
690
        -------
691
        :class:`~pincer.objects.guild.role.Role`
692
            The edited role object.
693
        """
694
        ...
695
696
    async def edit_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
697
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
698
        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...
699
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
700
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
701
    ) -> Role:
702
        return Role.from_dict(
703
            construct_client_dict(
704
                self._client,
705
                await self._http.patch(
706
                    f"guilds/{self.id}/roles/{id}",
707
                    data=kwargs,
708
                    headers=remove_none({"X-Audit-Log-Reason": reason})
709
                ),
710
            )
711
        )
712
713
    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...
714
        """|coro|
715
        Deletes a role.
716
        Requires the `MANAGE_ROLES` permission.
717
718
        Parameters
719
        ----------
720
        id : :class:`~pincer.utils.snowflake.Snowflake`
721
            The role ID
722
        reason : Optional[:class:`str`]
723
            The reason for deleting the role |default| :data:`None`
724
        """
725
        await self._http.delete(
726
            f"guilds/{self.id}/roles/{id}",
727
            headers=remove_none({"X-Audit-Log-Reason": reason})
728
        )
729
730
    async def get_bans(self) -> AsyncGenerator[Ban, None]:
731
        """|coro|
732
        Fetches all the bans in the guild.
733
734
        Yields
735
        -------
736
        AsyncGenerator[:class:`~pincer.objects.guild.ban.Ban`, :data:`None`]
737
            An async generator of Ban objects.
738
        """
739
        data = await self._http.get(f"guilds/{self.id}/bans")
740
        for ban_data in data:
741
            yield Ban.from_dict(construct_client_dict(self._client, ban_data))
742
743
    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...
744
        """|coro|
745
        Fetches a ban from the guild.
746
747
        Parameters
748
        ----------
749
        id : :class:`~pincer.utils.snowflake.Snowflake`
750
            The user ID
751
752
        Returns
753
        -------
754
        :class:`~pincer.objects.guild.ban.Ban`
755
            The Ban object.
756
        """
757
        return Ban.from_dict(
758
            construct_client_dict(
759
                self._client,
760
                await self._http.get(f"guilds/{self.id}/bans/{id}"),
761
            )
762
        )
763
764
    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...
765
        """|coro|
766
        Unbans a user from the guild.
767
768
        Parameters
769
        ----------
770
        id : :class:`~pincer.utils.snowflake.Snowflake`
771
            The user ID
772
        reason : Optional[:class:`str`]
773
            The reason for unbanning the user |default| :data:`None`
774
        """
775
        await self._http.delete(
776
            f"guilds/{self.id}/bans/{id}",
777
            headers=remove_none({"X-Audit-Log-Reason": reason})
778
        )
779
780
    @overload
781
    async def edit(
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (20/15).
Loading history...
782
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
783
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
784
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
785
        region: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
786
        verification_level: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
787
        default_message_notifications: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
788
        explicit_content_filter: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
789
        afk_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
790
        afk_timeout: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
791
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
792
        owner_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
793
        splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
794
        discovery_splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
795
        banner: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
796
        system_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
797
        system_channel_flags: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
798
        rules_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
799
        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...
800
        preferred_locale: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
801
        features: Optional[List[GuildFeature]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
802
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
803
    ) -> Guild:
804
        """|coro|
805
        Modifies the guild
806
807
        Parameters
808
        ----------
809
        name : Optional[:class:`str`]
810
            Guild name |default| :data:`None`
811
        region : Optional[:class:`str`]
812
            Guild voice region ID |default| :data:`None`
813
        verification_level : Optional[:class:`int`]
814
            Verification level |default| :data:`None`
815
        default_message_notifications : Optional[:class:`int`]
816
            Default message notification level |default| :data:`None`
817
        explicit_content_filter : Optional[:class:`int`]
818
            Explicit content filter level |default| :data:`None`
819
        afk_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
820
            ID for AFK channel |default| :data:`None`
821
        afk_timeout : Optional[:class:`int`]
822
            AFK timeout in seconds |default| :data:`None`
823
        icon : Optional[:class:`str`]
824
            base64 1024x1024 png/jpeg/gif image for the guild icon
825
            (can be animated gif when the server
826
            has the `ANIMATED_ICON` feature) |default| :data:`None`
827
        owner_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
828
            User ID to transfer guild ownership to (must be owner) |default| :data:`None`
829
        splash : Optional[:class:`str`]
830
            base64 16:9 png/jpeg image for the guild splash (when the
831
            server has the `INVITE_SPLASH` feature) |default| :data:`None`
832
        discovery_splash : Optional[:class:`str`]
833
            base64 16:9 png/jpeg image for the guild discovery splash
834
            (when the server has the `DISCOVERABLE` feature) |default| :data:`None`
835
        banner : Optional[:class:`str`]
836
            base64 16:9 png/jpeg image for the guild banner (when the
837
            server has the `BANNER` feature) |default| :data:`None`
838
        system_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
839
            The ID of the channel where guild notices such as welcome
840
            messages and boost events are posted |default| :data:`None`
841
        system_channel_flags : Optional[:class:`int`]
842
            System channel flags |default| :data:`None`
843
        rules_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
844
            The ID of the channel where Community guilds display rules
845
            and/or guidelines |default| :data:`None`
846
        public_updates_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
847
            The ID of the channel where admins and moderators of
848
            Community guilds receive notices from Discord |default| :data:`None`
849
        preferred_locale : Optional[:class:`str`]
850
            The preferred locale of a Community guild used in server
851
            discovery and notices from Discord; defaults to "en-US" |default| :data:`None`
852
        features : Optional[List[:class:`GuildFeature`]]
853
            Enabled guild features |default| :data:`None`
854
        description : Optional[:class:`str`]
855
            The description for the guild, if the guild is discoverable |default| :data:`None`
856
857
        Returns
858
        -------
859
        :class:`~pincer.objects.guild.Guild`
860
            The modified guild object.
861
        """
862
        ...
863
864
    async def edit(self, **kwargs) -> Guild:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
865
        g = await self._http.patch(f"guilds/{self.id}", data=kwargs)
866
        return Guild.from_dict(construct_client_dict(self._client, g))
867
868
    async def preview(self) -> GuildPreview:
869
        """|coro|
870
        Previews the guild.
871
872
        Returns
873
        -------
874
        :class:`~pincer.objects.guild.guild.GuildPreview`
875
            The guild preview object.
876
        """
877
        data = await self._http.get(f"guilds/{self.id}/preview")
878
        return GuildPreview.from_dict(data)
879
880
    async def delete(self):
881
        """|coro|
882
        Deletes the guild. Returns `204 No Content` on success.
883
        """
884
        await self._http.delete(f"guilds/{self.id}")
885
886
    async def prune_count(
887
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
888
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
889
        include_roles: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
890
    ) -> int:
891
        """|coro|
892
        Returns the number of members that
893
        would be removed in a prune operation.
894
        Requires the ``KICK_MEMBERS`` permission.
895
896
        Parameters
897
        ----------
898
        days : Optional[:class:`int`]
899
            Number of days to count prune for (1-30) |default| :data:`7`
900
        include_roles : Optional[:class:`str`]
901
            Comma-delimited array of Snowflakes;
902
            role(s) to include |default| :data:`None`
903
904
        Returns
905
        -------
906
        :class:`int`
907
            The number of members that would be removed.
908
        """
909
        return await self._http.get(
910
            f"guilds/{self.id}/prune?{days=}&{include_roles=!s}"
911
        )["pruned"]
912
913
    async def prune(
914
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
915
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
916
        compute_prune_days: Optional[bool] = True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
917
        include_roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
918
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
919
    ) -> int:
920
        """|coro|
921
        Prunes members from the guild. Requires the ``KICK_MEMBERS`` permission.
922
923
        Parameters
924
925
        Parameters
926
        ----------
927
        days : Optional[:class:`int`]
928
            Number of days to prune (1-30) |default| :data:`7`
929
        compute_prune_days : Optional[:class:`bool`]
930
            Whether ``pruned`` is returned, discouraged for large guilds
931
            |default| :data:`True`
932
        include_roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
933
            role(s) to include |default| :data:`None`
934
        reason : Optional[:class:`str`]
935
            Reason for the prune |default| :data:`None`
936
937
        Returns
938
        -------
939
        :class:`int`
940
            The number of members that were removed.
941
        """
942
        return await self._http.post(
943
            f"guilds/{self.id}/prune",
944
            data={
945
                "days": days,
946
                "compute_prune_days": compute_prune_days,
947
                "include_roles": include_roles
948
            },
949
            headers=remove_none({"X-Audit-Log-Reason": reason})
950
        )["pruned"]
951
952
    async def get_voice_regions(self) -> AsyncGenerator[VoiceRegion, None]:
953
        """|coro|
954
        Returns an async generator of voice regions.
955
956
        Yields
957
        -------
958
        AsyncGenerator[:class:`~pincer.objects.voice.VoiceRegion`, :data:`None`]
959
            An async generator of voice regions.
960
        """
961
        data = await self._http.get(f"guilds/{self.id}/regions")
962
        for voice_region_data in data:
963
            yield VoiceRegion.from_dict(construct_client_dict(self._client, voice_region_data))
964
965
    async def get_invites(self) -> AsyncGenerator[Invite, None]:
966
        """|coro|
967
        Returns an async generator of invites for the guild.
968
        Requires the ``MANAGE_GUILD`` permission.
969
970
        Yields
971
        -------
972
        AsyncGenerator[:class:`~pincer.objects.invite.Invite`, :data:`None`]
973
            An async generator of invites.
974
        """
975
        data = await self._http.get(f"guilds/{self.id}/invites")
976
        for invite_data in data:
977
            yield Invite.from_dict(construct_client_dict(self._client, invite_data))
978
979
    async def get_integrations(self) -> AsyncGenerator[Integration, None]:
980
        """|coro|
981
        Returns an async generator of integrations for the guild.
982
        Requires the ``MANAGE_GUILD`` permission.
983
984
        Yields
985
        -------
986
        AsyncGenerator[:class:`~pincer.objects.integration.Integration`, :data:`None`]
987
            An async generator of integrations.
988
        """
989
        data = await self._http.get(f"guilds/{self.id}/integrations")
990
        for integration_data in data:
991
            yield Integration.from_dict(construct_client_dict(self._client, integration_data))
992
993
    async def delete_integration(
994
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
995
        integration: Integration,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
996
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
997
    ):
998
        """|coro|
999
        Deletes an integration.
1000
        Requires the ``MANAGE_GUILD`` permission.
1001
1002
        Parameters
1003
        ----------
1004
        integration : :class:`~pincer.objects.integration.Integration`
1005
            The integration to delete.
1006
        reason : Optional[:class:`str`]
1007
            Reason for the deletion |default| :data:`None`
1008
        """
1009
        await self._http.delete(
1010
            f"guilds/{self.id}/integrations/{integration.id}",
1011
            headers=remove_none({"X-Audit-Log-Reason": reason})
1012
        )
1013
1014
    async def get_widget_settings(self) -> GuildWidget:
1015
        """|coro|
1016
        Returns the guild widget settings.
1017
        Requires the ``MANAGE_GUILD`` permission.
1018
1019
        Returns
1020
        -------
1021
        :class:`~pincer.objects.guild.widget.GuildWidget`
1022
            The guild widget settings.
1023
        """
1024
        return GuildWidget.from_dict(
1025
            construct_client_dict(
1026
                self._client,
1027
                await self._http.get(f"guilds/{self.id}/widget")
1028
            )
1029
        )
1030
1031
    async def modify_widget(
1032
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1033
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1034
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1035
    ) -> GuildWidget:
1036
        """|coro|
1037
        Modifies the guild widget for the guild.
1038
        Requires the ``MANAGE_GUILD`` permission.
1039
1040
        Parameters
1041
        ----------
1042
        reason : Optional[:class:`str`]
1043
            Reason for the modification |default| :data:`None`
1044
        \\*\\*kwargs
1045
            The widget settings to modify
1046
1047
        Returns
1048
        -------
1049
        :class:`~pincer.objects.guild.widget.GuildWidget`
1050
            The updated GuildWidget object
1051
        """
1052
        data = await self._http.patch(
1053
            f"guilds/{self.id}/widget",
1054
            data=kwargs,
1055
            headers=remove_none({"X-Audit-Log-Reason": reason})
1056
        )
1057
        return GuildWidget.from_dict(construct_client_dict(self._client, data))
1058
1059
    async def get_widget(self) -> Dict[str, JSONSerializable]:
1060
        """|coro|
1061
        Returns the widget for the guild
1062
        """
1063
        return await self._http.get(f"guilds/{self.id}/widget.json")
1064
1065
    @property
1066
    async def vanity_url(self) -> Invite:
1067
        """|coro|
1068
        Returns the Vanity URL for the guild.
1069
        Requires the ``MANAGE_GUILD`` permission.
1070
        ``code`` will be null if a vanity URL has not been set.
1071
1072
        Returns
1073
        -------
1074
        :class:`~pincer.objects.guild.invite.Invite`
1075
            The vanity url for the guild.
1076
        """
1077
        data = await self._http.get(f"guilds/{self.id}/vanity-url")
1078
        return Invite.from_dict(construct_client_dict(self._client, data))
1079
1080
    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...
1081
        """|coro|
1082
        Returns a PNG image widget for the guild.
1083
        Requires no permissions or authentication.
1084
1085
        Widget Style Options
1086
        -------------------
1087
        * [``shield``](https://discord.com/api/guilds/81384788765712384/widget.png?style=shield)
1088
          shield style widget with Discord icon and guild members online count
1089
        * [``banner1``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner1)
1090
          large image with guild icon, name and online count.
1091
          "POWERED BY DISCORD" as the footer of the widget
1092
        * [``banner2``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner2)
1093
          smaller widget style with guild icon, name and online count.
1094
          Split on the right with Discord logo
1095
        * [``banner3``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner3)
1096
          large image with guild icon, name and online count.
1097
          In the footer, Discord logo on the
1098
          left and "Chat Now" on the right
1099
        * [``banner4``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner4)
1100
          large Discord logo at the top of the widget.
1101
          Guild icon, name and online count in the middle portion
1102
          of the widget and a "JOIN MY SERVER" button at the bottom
1103
1104
        Parameters
1105
        ----------
1106
        style : Optional[:class:`str`]
1107
            Style of the widget image returned |default| :data:`"shield"`
1108
1109
        Returns
1110
        -------
1111
        :class:`str`
1112
            A PNG image of the guild widget.
1113
        """
1114
        return await self._http.get(f"guilds/{self.id}/widget.png?{style=!s}")
1115
1116
    async def get_welcome_screen(self) -> WelcomeScreen:
1117
        """Returns the welcome screen for the guild.
1118
1119
        Returns
1120
        -------
1121
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1122
            The welcome screen for the guild.
1123
        """
1124
        data = await self._http.get(f"guilds/{self.id}/welcome-screen")
1125
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1126
1127
    async def modify_welcome_screen(
1128
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1129
        enabled: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1130
        welcome_channels: Optional[List[WelcomeScreenChannel]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1131
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1132
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1133
    ) -> WelcomeScreen:
1134
        """|coro|
1135
        Modifies the guild's Welcome Screen.
1136
        Requires the ``MANAGE_GUILD`` permission.
1137
1138
        Parameters
1139
        ----------
1140
        enabled : Optional[:class:`bool`]
1141
            Whether the welcome screen is enabled |default| :data:`None`
1142
        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...
1143
            Channels linked in the welcome screen and
1144
            their display options |default| :data:`None`
1145
        description : Optional[:class:`str`]
1146
            The server description to show
1147
            in the welcome screen |default| :data:`None`
1148
        reason : Optional[:class:`str`]
1149
            Reason for the modification |default| :data:`None`
1150
1151
        Returns
1152
        -------
1153
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1154
            The updated WelcomeScreen object
1155
        """
1156
        data = await self._http.patch(
1157
            f"guilds/{self.id}/welcome-screen",
1158
            data={
1159
                "enabled": enabled,
1160
                "welcome_channels": welcome_channels,
1161
                "description": description
1162
            },
1163
            headers=remove_none({"X-Audit-Log-Reason": reason})
1164
        )
1165
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1166
1167
    async def modify_current_user_voice_state(
1168
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1169
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1170
        suppress: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1171
        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...
1172
    ):
1173
        """|coro|
1174
        Updates the current user's voice state.
1175
1176
        There are currently several caveats for this endpoint:
1177
        * ``channel_id`` must currently point to a stage channel
1178
        * current user must already have joined ``channel_id``
1179
        * You must have the ``MUTE_MEMBERS`` permission to
1180
          unsuppress yourself. You can always suppress yourself.
1181
        * You must have the ``REQUEST_TO_SPEAK`` permission to request
1182
          to speak. You can always clear your own request to speak.
1183
        * You are able to set ``request_to_speak_timestamp`` to any
1184
          present or future time.
1185
1186
        Parameters
1187
        ----------
1188
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1189
            The ID of the channel the user is currently in
1190
        suppress : Optional[:class:`bool`]
1191
            Toggles the user's suppress state |default| :data:`None`
1192
        request_to_speak_timestamp : Optional[:class:`~pincer.utils.timestamp.Timestamp`]
1193
            Sets the user's request to speak
1194
        """
1195
        await self._http.patch(
1196
            f"guilds/{self.id}/voice-states/@me",
1197
            data={
1198
                "channel_id": channel_id,
1199
                "suppress": suppress,
1200
                "request_to_speak_timestamp": request_to_speak_timestamp
1201
            }
1202
        )
1203
1204
    async def modify_user_voice_state(
1205
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1206
        user: User,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1207
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1208
        suppress: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1209
    ):
1210
        """|coro|
1211
        Updates another user's voice state.
1212
1213
        There are currently several caveats for this endpoint:
1214
        * ``channel_id`` must currently point to a stage channel
1215
        * User must already have joined ``channel_id``
1216
        * You must have the ``MUTE_MEMBERS`` permission.
1217
          (Since suppression is the only thing that is available currently.)
1218
        * When unsuppressed, non-bot users will have their
1219
          ``request_to_speak_timestamp`` set to the current time.
1220
          Bot users will not.
1221
        * When suppressed, the user will have their
1222
          ``request_to_speak_timestamp`` removed.
1223
1224
        Parameters
1225
        ----------
1226
        user : :class:`~pincer.objects.guild.member.Member`
1227
            The user to update
1228
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1229
            The ID of the channel the user is currently in
1230
        suppress : Optional[:class:`bool`]
1231
            Toggles the user's suppress state |default| :data:`None`
1232
        """
1233
        await self._http.patch(
1234
            f"guilds/{self.id}/voice-states/{user.id}",
1235
            data={
1236
                "channel_id": channel_id,
1237
                "suppress": suppress
1238
            }
1239
        )
1240
1241
    async def get_audit_log(self) -> AuditLog:
1242
        """|coro|
1243
        Returns an audit log object for the guild.
1244
        Requires the ``VIEW_AUDIT_LOG`` permission.
1245
1246
        Returns
1247
        -------
1248
        :class:`~pincer.objects.guild.audit_log.AuditLog`
1249
            The audit log object for the guild.
1250
        """
1251
        return AuditLog.from_dict(
1252
            construct_client_dict(
1253
                self._client,
1254
                await self._http.get(f"guilds/{self.id}/audit-logs")
1255
            )
1256
        )
1257
1258
    async def get_emojis(self) -> AsyncGenerator[Emoji, None]:
1259
        """|coro|
1260
        Returns an async generator of the emojis in the guild.
1261
1262
        Yields
1263
        ------
1264
        :class:`~pincer.objects.guild.emoji.Emoji`
1265
            The emoji object.
1266
        """
1267
        data = await self._http.get(f"guilds/{self.id}/emojis")
1268
        for emoji_data in data:
1269
            yield Emoji.from_dict(
1270
                construct_client_dict(self._client, emoji_data)
1271
            )
1272
1273
    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...
1274
        """|coro|
1275
        Returns an emoji object for the given ID.
1276
1277
        Parameters
1278
        ----------
1279
        id : :class:`~pincer.utils.snowflake.Snowflake`
1280
            The ID of the emoji
1281
1282
        Returns
1283
        -------
1284
        :class:`~pincer.objects.guild.emoji.Emoji`
1285
            The emoji object.
1286
        """
1287
        return Emoji.from_dict(
1288
            construct_client_dict(
1289
                self._client,
1290
                await self._http.get(f"guilds/{self.id}/emojis/{id}")
1291
            )
1292
        )
1293
1294
    async def create_emoji(
1295
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1296
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1297
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1298
        image: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1299
        roles: List[Snowflake],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1300
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1301
    ) -> Emoji:
1302
        """|coro|
1303
        Creates a new emoji for the guild.
1304
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1305
1306
        Emojis and animated emojis have a maximum file size of 256kb.
1307
        Attempting to upload an emoji larger than this limit will fail.
1308
1309
        Parameters
1310
        ----------
1311
        name : :class:`str`
1312
            Name of the emoji
1313
        image : :class:`str`
1314
            The 128x128 emoji image data
1315
        roles : List[:class:`~pincer.utils.snowflake.Snowflake`]
1316
            Roles allowed to use this emoji
1317
        reason : Optional[:class:`str`]
1318
            The reason for creating the emoji |default| :data:`None`
1319
1320
        Returns
1321
        -------
1322
        :class:`~pincer.objects.guild.emoji.Emoji`
1323
            The newly created emoji object.
1324
        """
1325
        data = await self._http.post(
1326
            f"guilds/{self.id}/emojis",
1327
            data={
1328
                "name": name,
1329
                "image": image,
1330
                "roles": roles
1331
            },
1332
            headers=remove_none({"X-Audit-Log-Reason": reason})
1333
        )
1334
        return Emoji.from_dict(
1335
            construct_client_dict(self._client, data)
1336
        )
1337
1338
    async def edit_emoji(
1339
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1340
        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...
1341
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1342
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1343
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1344
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1345
    ) -> Emoji:
1346
        """|coro|
1347
        Modifies the given emoji.
1348
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1349
1350
        Parameters
1351
        ----------
1352
        id : :class:`~pincer.utils.snowflake.Snowflake`
1353
            The ID of the emoji
1354
        name : Optional[:class:`str`]
1355
            Name of the emoji |default| :data:`None`
1356
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1357
            Roles allowed to use this emoji |default| :data:`None`
1358
        reason : Optional[:class:`str`]
1359
            The reason for editing the emoji |default| :data:`None`
1360
1361
        Returns
1362
        -------
1363
        :class:`~pincer.objects.guild.emoji.Emoji`
1364
            The modified emoji object.
1365
        """
1366
        data = await self._http.patch(
1367
            f"guilds/{self.id}/emojis/{id}",
1368
            data={
1369
                "name": name,
1370
                "roles": roles
1371
            },
1372
            headers=remove_none({"X-Audit-Log-Reason": reason})
1373
        )
1374
        return Emoji.from_dict(
1375
            construct_client_dict(self._client, data)
1376
        )
1377
1378
    async def delete_emoji(
1379
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1380
        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...
1381
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1382
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1383
    ):
1384
        """|coro|
1385
        Deletes the given emoji.
1386
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1387
1388
        Parameters
1389
        ----------
1390
        id : :class:`~pincer.utils.snowflake.Snowflake`
1391
            The ID of the emoji
1392
        reason : Optional[:class:`str`]
1393
            The reason for deleting the emoji |default| :data:`None`
1394
        """
1395
        await self._http.delete(
1396
            f"guilds/{self.id}/emojis/{id}",
1397
            headers=remove_none({"X-Audit-Log-Reason": reason})
1398
        )
1399
1400
    async def get_templates(self) -> AsyncGenerator[GuildTemplate, None]:
1401
        """|coro|
1402
        Returns an async generator of the guild templates.
1403
1404
        Yields
1405
        -------
1406
        AsyncGenerator[:class:`~pincer.objects.guild.template.GuildTemplate`, :data:`None`]
1407
            The guild template object.
1408
        """
1409
        data = await self._http.get(f"guilds/{self.id}/templates")
1410
        for template_data in data:
1411
            yield GuildTemplate.from_dict(
1412
                construct_client_dict(self._client, template_data)
1413
            )
1414
1415
    async def create_template(
1416
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1417
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1418
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1419
    ) -> GuildTemplate:
1420
        """|coro|
1421
        Creates a new template for the guild.
1422
        Requires the ``MANAGE_GUILD`` permission.
1423
1424
        Parameters
1425
        ----------
1426
        name : :class:`str`
1427
            Name of the template (1-100 characters)
1428
        description : Optional[:class:`str`]
1429
            Description of the template
1430
            (0-120 characters) |default| :data:`None`
1431
        Returns
1432
        -------
1433
        :class:`~pincer.objects.guild.template.GuildTemplate`
1434
            The newly created template object.
1435
        """
1436
        data = await self._http.post(
1437
            f"guilds/{self.id}/templates",
1438
            data={
1439
                "name": name,
1440
                "description": description
1441
            }
1442
        )
1443
        return GuildTemplate.from_dict(
1444
            construct_client_dict(self._client, data)
1445
        )
1446
1447
    async def sync_template(
1448
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1449
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1450
    ) -> GuildTemplate:
1451
        """|coro|
1452
        Syncs the given template.
1453
        Requires the ``MANAGE_GUILD`` permission.
1454
1455
        Parameters
1456
        ----------
1457
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1458
            The template to sync
1459
1460
        Returns
1461
        -------
1462
        :class:`~pincer.objects.guild.template.GuildTemplate`
1463
            The synced template object.
1464
        """
1465
        data = await self._http.put(
1466
            f"guilds/{self.id}/templates/{template.code}"
1467
        )
1468
        return GuildTemplate.from_dict(
1469
            construct_client_dict(self._client, data)
1470
        )
1471
1472
    async def edit_template(
1473
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1474
        template: GuildTemplate,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1475
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1476
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1477
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1478
    ) -> GuildTemplate:
1479
        """|coro|
1480
        Modifies the template's metadata.
1481
        Requires the ``MANAGE_GUILD`` permission.
1482
1483
        Parameters
1484
        ----------
1485
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1486
            The template to edit
1487
        name : Optional[:class:`str`]
1488
            Name of the template (1-100 characters)
1489
            |default| :data:`None`
1490
        description : Optional[:class:`str`]
1491
            Description of the template (0-120 characters)
1492
            |default| :data:`None`
1493
1494
        Returns
1495
        -------
1496
        :class:`~pincer.objects.guild.template.GuildTemplate`
1497
            The edited template object.
1498
        """
1499
        data = await self._http.patch(
1500
            f"guilds/{self.id}/templates/{template.code}",
1501
            data={
1502
                "name": name,
1503
                "description": description
1504
            }
1505
        )
1506
        return GuildTemplate.from_dict(
1507
            construct_client_dict(self._client, data)
1508
        )
1509
1510
    async def delete_template(
1511
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1512
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1513
    ) -> GuildTemplate:
1514
        """|coro|
1515
        Deletes the given template.
1516
        Requires the ``MANAGE_GUILD`` permission.
1517
1518
        Parameters
1519
        ----------
1520
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1521
            The template to delete
1522
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1523
        Returns
1524
        -------
1525
        :class:`~pincer.objects.guild.template.GuildTemplate`
1526
            The deleted template object.
1527
        """
1528
        data = await self._http.delete(
1529
            f"guilds/{self.id}/templates/{template.code}"
1530
        )
1531
        return GuildTemplate.from_dict(
1532
            construct_client_dict(self._client, data)
1533
        )
1534
1535
    @classmethod
1536
    def from_dict(cls, data) -> Guild:
1537
        """
1538
        Parameters
1539
        ----------
1540
        data : :class:`Dict`
1541
            Guild data received from the discord API.
1542
        Returns
1543
        -------
1544
        :class:`~pincer.objects.guild.guild.Guild`
1545
            The new guild object.
1546
        Raises
1547
        :class:`~pincer.exceptions.UnavailableGuildError`
1548
            The guild is unavailable due to a discord outage.
1549
        """
1550
        if data.get("unavailable", False):
1551
            raise UnavailableGuildError(
1552
                f"Guild \"{data['id']}\" is unavailable due to a discord"
1553
                " outage."
1554
            )
1555
1556
        return super().from_dict(data)
1557
1558
1559
@dataclass
1560
class UnavailableGuild(APIObject):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
1561
    id: Snowflake
1562
    unavailable: bool = True
1563