Passed
Pull Request — main (#281)
by
unknown
02:25
created

Guild.get_voice_regions()   A

Complexity

Conditions 2

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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