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

pincer.objects.guild.guild   F

Complexity

Total Complexity 61

Size/Duplication

Total Lines 1584
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 61
eloc 512
dl 0
loc 1584
rs 3.52
c 0
b 0
f 0

44 Methods

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

How to fix   Complexity   

Complexity

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

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

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

Objects as default values are only created once in Python and not on each invocation of the function. If the default object is modified, this modification is carried over to the next invocation of the method.

# Bad:
# If array_param is modified inside the function, the next invocation will
# receive the modified object.
def some_function(array_param=[]):
    # ...

# Better: Create an array on each invocation
def some_function(array_param=None):
    array_param = array_param or []
    # ...
Loading history...
1301
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1302
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1303
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1304
        image: File,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1305
        roles: List[Snowflake] = [],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1306
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1307
    ) -> Emoji:
1308
        """|coro|
1309
        Creates a new emoji for the guild.
1310
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1311
1312
        Emojis and animated emojis have a maximum file size of 256kb.
1313
        Attempting to upload an emoji larger than this limit will fail.
1314
1315
        Parameters
1316
        ----------
1317
        name : :class:`str`
1318
            Name of the emoji
1319
        image : :class:`~pincer.objects.message.file.File`
1320
            The File for the 128x128 emoji image data
1321
        roles : List[:class:`~pincer.utils.snowflake.Snowflake`]
1322
            Roles allowed to use this emoji |default| :data:`[]`
1323
        reason : Optional[:class:`str`]
1324
            The reason for creating the emoji |default| :data:`None`
1325
1326
        Returns
1327
        -------
1328
        :class:`~pincer.objects.guild.emoji.Emoji`
1329
            The newly created emoji object.
1330
        """
1331
        data = await self._http.post(
1332
            f"guilds/{self.id}/emojis",
1333
            data={
1334
                "name": name,
1335
                "image": image.uri,
1336
                "roles": roles
1337
            },
1338
            headers=remove_none({"X-Audit-Log-Reason": reason})
1339
        )
1340
        return Emoji.from_dict(
1341
            construct_client_dict(self._client, data)
1342
        )
1343
1344
    async def edit_emoji(
1345
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1346
        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...
1347
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1348
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1349
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1350
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1351
    ) -> Emoji:
1352
        """|coro|
1353
        Modifies the given emoji.
1354
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1355
1356
        Parameters
1357
        ----------
1358
        id : :class:`~pincer.utils.snowflake.Snowflake`
1359
            The ID of the emoji
1360
        name : Optional[:class:`str`]
1361
            Name of the emoji |default| :data:`None`
1362
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1363
            Roles allowed to use this emoji |default| :data:`None`
1364
        reason : Optional[:class:`str`]
1365
            The reason for editing the emoji |default| :data:`None`
1366
1367
        Returns
1368
        -------
1369
        :class:`~pincer.objects.guild.emoji.Emoji`
1370
            The modified emoji object.
1371
        """
1372
        data = await self._http.patch(
1373
            f"guilds/{self.id}/emojis/{id}",
1374
            data={
1375
                "name": name,
1376
                "roles": roles
1377
            },
1378
            headers=remove_none({"X-Audit-Log-Reason": reason})
1379
        )
1380
        return Emoji.from_dict(
1381
            construct_client_dict(self._client, data)
1382
        )
1383
1384
    async def delete_emoji(
1385
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1386
        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...
1387
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1388
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1389
    ):
1390
        """|coro|
1391
        Deletes the given emoji.
1392
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1393
1394
        Parameters
1395
        ----------
1396
        id : :class:`~pincer.utils.snowflake.Snowflake`
1397
            The ID of the emoji
1398
        reason : Optional[:class:`str`]
1399
            The reason for deleting the emoji |default| :data:`None`
1400
        """
1401
        await self._http.delete(
1402
            f"guilds/{self.id}/emojis/{id}",
1403
            headers=remove_none({"X-Audit-Log-Reason": reason})
1404
        )
1405
1406
    async def get_templates(self) -> AsyncGenerator[GuildTemplate, None]:
1407
        """|coro|
1408
        Returns an async generator of the guild templates.
1409
1410
        Yields
1411
        -------
1412
        AsyncGenerator[:class:`~pincer.objects.guild.template.GuildTemplate`, :data:`None`]
1413
            The guild template object.
1414
        """
1415
        data = await self._http.get(f"guilds/{self.id}/templates")
1416
        for template_data in data:
1417
            yield GuildTemplate.from_dict(
1418
                construct_client_dict(self._client, template_data)
1419
            )
1420
1421
    async def create_template(
1422
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1423
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1424
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1425
    ) -> GuildTemplate:
1426
        """|coro|
1427
        Creates a new template for the guild.
1428
        Requires the ``MANAGE_GUILD`` permission.
1429
1430
        Parameters
1431
        ----------
1432
        name : :class:`str`
1433
            Name of the template (1-100 characters)
1434
        description : Optional[:class:`str`]
1435
            Description of the template
1436
            (0-120 characters) |default| :data:`None`
1437
        Returns
1438
        -------
1439
        :class:`~pincer.objects.guild.template.GuildTemplate`
1440
            The newly created template object.
1441
        """
1442
        data = await self._http.post(
1443
            f"guilds/{self.id}/templates",
1444
            data={
1445
                "name": name,
1446
                "description": description
1447
            }
1448
        )
1449
        return GuildTemplate.from_dict(
1450
            construct_client_dict(self._client, data)
1451
        )
1452
1453
    async def sync_template(
1454
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1455
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1456
    ) -> GuildTemplate:
1457
        """|coro|
1458
        Syncs the given template.
1459
        Requires the ``MANAGE_GUILD`` permission.
1460
1461
        Parameters
1462
        ----------
1463
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1464
            The template to sync
1465
1466
        Returns
1467
        -------
1468
        :class:`~pincer.objects.guild.template.GuildTemplate`
1469
            The synced template object.
1470
        """
1471
        data = await self._http.put(
1472
            f"guilds/{self.id}/templates/{template.code}"
1473
        )
1474
        return GuildTemplate.from_dict(
1475
            construct_client_dict(self._client, data)
1476
        )
1477
1478
    async def edit_template(
1479
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1480
        template: GuildTemplate,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1481
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1482
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1483
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1484
    ) -> GuildTemplate:
1485
        """|coro|
1486
        Modifies the template's metadata.
1487
        Requires the ``MANAGE_GUILD`` permission.
1488
1489
        Parameters
1490
        ----------
1491
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1492
            The template to edit
1493
        name : Optional[:class:`str`]
1494
            Name of the template (1-100 characters)
1495
            |default| :data:`None`
1496
        description : Optional[:class:`str`]
1497
            Description of the template (0-120 characters)
1498
            |default| :data:`None`
1499
1500
        Returns
1501
        -------
1502
        :class:`~pincer.objects.guild.template.GuildTemplate`
1503
            The edited template object.
1504
        """
1505
        data = await self._http.patch(
1506
            f"guilds/{self.id}/templates/{template.code}",
1507
            data={
1508
                "name": name,
1509
                "description": description
1510
            }
1511
        )
1512
        return GuildTemplate.from_dict(
1513
            construct_client_dict(self._client, data)
1514
        )
1515
1516
    async def delete_template(
1517
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1518
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1519
    ) -> GuildTemplate:
1520
        """|coro|
1521
        Deletes the given template.
1522
        Requires the ``MANAGE_GUILD`` permission.
1523
1524
        Parameters
1525
        ----------
1526
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1527
            The template to delete
1528
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1529
        Returns
1530
        -------
1531
        :class:`~pincer.objects.guild.template.GuildTemplate`
1532
            The deleted template object.
1533
        """
1534
        data = await self._http.delete(
1535
            f"guilds/{self.id}/templates/{template.code}"
1536
        )
1537
        return GuildTemplate.from_dict(
1538
            construct_client_dict(self._client, data)
1539
        )
1540
1541
    async def get_webhooks(self) -> AsyncGenerator[Webhook, None]:
1542
        """|coro|
1543
        Returns an async generator of the guild webhooks.
1544
1545
        Yields
1546
        -------
1547
        AsyncGenerator[:class:`~pincer.objects.guild.webhook.Webhook`, None]
1548
            The guild webhook object.
1549
        """
1550
        data = await self._http.get(f"guilds/{self.id}/webhooks")
1551
        for webhook_data in data:
1552
            yield Webhook.from_dict(
1553
                construct_client_dict(self._client, webhook_data)
1554
            )
1555
1556
    @classmethod
1557
    def from_dict(cls, data) -> Guild:
1558
        """
1559
        Parameters
1560
        ----------
1561
        data : :class:`Dict`
1562
            Guild data received from the discord API.
1563
        Returns
1564
        -------
1565
        :class:`~pincer.objects.guild.guild.Guild`
1566
            The new guild object.
1567
        Raises
1568
        :class:`~pincer.exceptions.UnavailableGuildError`
1569
            The guild is unavailable due to a discord outage.
1570
        """
1571
        if data.get("unavailable", False):
1572
            raise UnavailableGuildError(
1573
                f"Guild \"{data['id']}\" is unavailable due to a discord"
1574
                " outage."
1575
            )
1576
1577
        return super().from_dict(data)
1578
1579
1580
@dataclass(repr=False)
1581
class UnavailableGuild(APIObject):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
1582
    id: Snowflake
1583
    unavailable: bool = True
1584