Passed
Pull Request — main (#281)
by
unknown
01:48
created

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

Complexity

Conditions 2

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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