Passed
Pull Request — main (#238)
by
unknown
01:45
created

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

Complexity

Conditions 1

Size

Total Lines 46
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 46
rs 10
c 0
b 0
f 0
cc 1
nop 3
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
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 overload, TYPE_CHECKING
9
10
from .ban import Ban
11
from .channel import Channel
0 ignored issues
show
introduced by
Cannot import 'channel' due to syntax error 'invalid syntax (<unknown>, line 269)'
Loading history...
12
from .member import GuildMember
13
from ...exceptions import UnavailableGuildError
14
from ...utils.api_object import APIObject
0 ignored issues
show
Bug introduced by
The name api_object does not seem to exist in module pincer.utils.
Loading history...
introduced by
Cannot import 'utils.api_object' due to syntax error 'invalid syntax (<unknown>, line 80)'
Loading history...
15
from ...utils.conversion import construct_client_dict
16
from ...utils.types import MISSING
17
18
if TYPE_CHECKING:
19
    from typing import Any, Dict, List, Optional, Union
20
21
    from .features import GuildFeature
22
    from .role import Role
23
    from .stage import StageInstance
24
    from .welcome_screen import WelcomeScreen
25
    from ..events.presence import PresenceUpdateEvent
26
    from ..message.emoji import Emoji
27
    from ..message.sticker import Sticker
28
    from ..user.voice_state import VoiceState
29
    from ...client import Client
0 ignored issues
show
introduced by
Cannot import 'client' due to syntax error 'invalid syntax (<unknown>, line 354)'
Loading history...
30
    from ...utils.timestamp import Timestamp
0 ignored issues
show
Bug introduced by
The name timestamp does not seem to exist in module pincer.utils.
Loading history...
introduced by
Cannot import 'utils.timestamp' due to syntax error 'invalid syntax (<unknown>, line 116)'
Loading history...
31
    from ...utils.types import APINullable
32
    from ...utils.snowflake import Snowflake
33
34
35
class PremiumTier(IntEnum):
36
    """Represents the boost tier of a guild.
37
    Attributes
38
    ----------
39
    NONE:
40
        Guild has not unlocked any Server Boost perks.
41
    TIER_1:
42
        Guild has unlocked Server Boost level 1 perks.
43
    TIER_2:
44
        Guild has unlocked Server Boost level 2 perks.
45
    TIER_3:
46
        Guild has unlocked Server Boost level 3 perks.
47
    """
48
    NONE = 0
49
    TIER_1 = 1
50
    TIER_2 = 2
51
    TIER_3 = 3
52
53
54
class GuildNSFWLevel(IntEnum):
55
    """Represents the NSFW level of a guild.
56
    Attributes
57
    ----------
58
    DEFAULT:
59
        Default NSFW level.
60
    EXPLICIT:
61
        Explicit NSFW level.
62
    SAFE:
63
        SAFE NSFW level.
64
    AGE_RESTRICTED:
65
        Age restricted NSFW level.
66
    """
67
    DEFAULT = 0
68
    EXPLICIT = 1
69
    SAFE = 2
70
    AGE_RESTRICTED = 3
71
72
73
class ExplicitContentFilterLevel(IntEnum):
74
    """Represents the filter content level of a guild.
75
    Attributes
76
    ----------
77
    DISABLED:
78
        Media content will not be scanned.
79
    MEMBERS_WITHOUT_ROLES:
80
        Media content sent by members without roles will be scanned.
81
    ALL_MEMBERS:
82
        Media content sent by all members will be scanned.
83
    """
84
    DISABLED = 0
85
    MEMBERS_WITHOUT_ROLES = 1
86
    ALL_MEMBERS = 2
87
88
89
class MFALevel(IntEnum):
90
    """Represents the multi factor authentication level of a guild.
91
    Attributes
92
    ----------
93
    NONE:
94
        Guild has no MFA/2FA requirement for moderation actions.
95
    ELEVATED:
96
        Guild has a 2FA requirement for moderation actions
97
    """
98
    NONE = 0
99
    ELEVATED = 1
100
101
102
class VerificationLevel(IntEnum):
103
    """Represents the verification level of a guild.
104
    Attributes
105
    ----------
106
    NONE:
107
        Unrestricted.
108
    LOW:
109
        Must have verified email on account.
110
    MEDIUM:
111
        Must be registered on Discord for longer than 5 minutes.
112
    HIGH:
113
        Must be a member of the server for longer than 10 minutes.
114
    VERY_HIGH:
115
        Must have a verified phone number.
116
    """
117
    NONE = 0
118
    LOW = 1
119
    MEDIUM = 2
120
    HIGH = 3
121
    VERY_HIGH = 4
122
123
124
class DefaultMessageNotificationLevel(IntEnum):
125
    """Represents the default message notification level of a guild.
126
    Attributes
127
    ----------
128
    ALL_MESSAGES:
129
        Members will receive notifications for all messages by default.
130
    ONLY_MENTIONS:
131
        Members will receive notifications only for messages that @mention them by default.
132
    """
133
    # noqa: E501
134
    ALL_MESSAGES = 0
135
    ONLY_MENTIONS = 1
136
137
138
class SystemChannelFlags(IntEnum):
139
    """Represents the system channel flags of a guild.
140
    Attributes
141
    ----------
142
    SUPPRESS_JOIN_NOTIFICATIONS:
143
        Suppress member join notifications.
144
    SUPPRESS_PREMIUM_SUBSCRIPTIONS:
145
        Suppress server boost notifications.
146
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS:
147
        Suppress server setup tips.
148
    SUPPRESS_JOIN_NOTIFICATION_REPLIES:
149
        Hide member join sticker reply buttons
150
    """
151
    SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0
152
    SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
153
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS = 1 << 2
154
    SUPPRESS_JOIN_NOTIFICATION_REPLIES = 1 << 3
155
156
157
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (10/7)
Loading history...
158
class GuildPreview(APIObject):
159
    """Represents a guild preview.
160
    Attributes
161
    ----------
162
    id: :class:`Snowflake`
163
        The guild ID.
164
    name: :class:`str`
165
        The guild name.
166
    icon: :class:`str`
167
        The guild icon hash.
168
    splash: :class:`str`
169
        The guild splash hash.
170
    discovery_splash: :class:`str`
171
        The guild discovery splash hash.
172
    emojis: :class:`List[Emoji]`
173
        The guild emojis.
174
    features: :class:`List[GuildFeature]`
175
        The guild features.
176
    approximate_member_count: :class:`int`
177
        The approximate member count.
178
    approximate_presence_count: :class:`int`
179
        The approximate number of online members in this guild
180
    description: :class:`str`
181
        The guild description.
182
    """
183
    id: Snowflake
184
    name: str
185
    emojis: List[Emoji]
186
    features: List[GuildFeature]
187
    approximate_member_count: int
188
    approximate_presence_count: int
189
190
    icon: APINullable[str] = MISSING
191
    splash: APINullable[str] = MISSING
192
    discovery_splash: APINullable[str] = MISSING
193
    description: APINullable[str] = MISSING
194
195
196
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (59/7)
Loading history...
197
class Guild(APIObject):
198
    """Represents a Discord guild/server in which your client resides.
199
    Attributes
200
    ----------
201
    afk_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
202
        Id of afk channel
203
    afk_timeout: :class:`int`
204
        Afk timeout in seconds
205
    application_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
206
        Application id of the guild creator if it is bot-created
207
    banner: Optional[:class:`str`]
208
        Banner hash
209
    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...
210
        Default message notifications level
211
    description: Optional[:class:`str`]
212
        The description of a Community guild
213
    discovery_splash: Optional[:class:`str`]
214
        Discovery splash hash;
215
        only present for guilds with the "DISCOVERABLE" feature
216
    emojis: List[:class:`~pincer.objects.message.emoji.Emoji`]
217
        Custom guild emojis
218
    explicit_content_filter: :class:`~pincer.objects.guild.guild.ExplicitContentFilterLevel`
219
        Explicit content filter level
220
    features: List[:class:`~pincer.objects.guild.features.GuildFeature`]
221
        Enabled guild features
222
    id: :class:`~pincer.utils.snowflake.Snowflake`
223
        Guild id
224
    icon: Optional[:class:`str`]
225
        Icon hash
226
    mfa_level: :class:`~pincer.objects.guild.guild.MFALevel`
227
        Required MFA level for the guild
228
    name: :class:`str`
229
        Guild name (2-100 characters, excluding trailing and leading
230
        whitespace)
231
    nsfw_level: :class:`~pincer.objects.guild.guild.NSFWLevel`
232
        Guild NSFW level
233
    owner_id: :class:`~pincer.utils.snowflake.Snowflake`
234
        Id of owner
235
    preferred_locale: :class:`str`
236
        The preferred locale of a Community guild;
237
        used in server discovery and notices from Discord;
238
        defaults to "en-US"
239
    premium_tier: :class:`~pincer.objects.guild.guild.PremiumTier`
240
        Premium tier (Server Boost level)
241
    public_updates_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
242
        The id of the channel where admins
243
        and moderators of Community guilds receive notices from Discord
244
    roles: List[:class:`~pincer.objects.guild.role.Role`]
245
        Roles in the guild
246
    rules_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
247
        The id of the channel where Community guilds can display rules
248
        and/or guidelines
249
    splash: Optional[:class:`str`]
250
        Splash hash
251
    system_channel_flags: :class:`~pincer.objects.guild.guild.SystemChannelFlags`
252
        System channel flags
253
    system_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
254
        The id of the channel where guild notices
255
        such as welcome messages and boost events are posted
256
    vanity_url_code: Optional[:class:`str`]
257
        The vanity url code for the guild
258
    verification_level: :class:`~pincer.objects.guild.guild.VerificationLevel`
259
        Verification level required for the guild
260
    approximate_member_count: APINullable[:class:`int`]
261
        Approximate number of members in this guild, returned from the
262
        `GET /guilds/<id>` endpoint when with_counts is true
263
    approximate_presence_count: APINullable[:class:`int`]
264
        Approximate number of non-offline members in this guild,
265
        returned from the `GET /guilds/<id>`
266
        endpoint when with_counts is true
267
    channels: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
268
        Channels in the guild
269
    icon_hash: APINullable[Optional[:class:`str`]]
270
        Icon hash, returned when in the template object
271
    joined_at: APINullable[:class:`~pincer.utils.timestamp.Timestamp`]
272
        When this guild was joined at
273
    large: APINullable[:class:`bool`]
274
        True if this is considered a large guild
275
    max_members: APINullable[:class:`int`]
276
        The maximum number of members for the guild
277
    max_presences: APINullable[Optional[:class:`int`]]
278
        The maximum number of presences for the guild
279
        (null is always returned, apart from the largest of guilds)
280
    max_video_channel_users: APINullable[:class:`int`]
281
        The maximum amount of users in a video channel
282
    members: APINullable[List[:class:`~pincer.objects.guild.member.GuildMember`]]
283
        Users in the guild
284
    member_count: APINullable[:class:`bool`]
285
        Total number of members in this guild
286
    nsfw: APINullable[:class:`bool`]
287
        Boolean if the server is NSFW
288
    owner: APINullable[:class:`bool`]
289
        True if the user is the owner of the guild
290
    permissions: APINullable[:class:`str`]
291
        Total permissions for the user in the guild
292
        (excludes overwrites)
293
    premium_subscription_count: APINullable[:class:`int`]
294
        The number of boosts this guild currently has
295
    presences: APINullable[List[:class:`~pincer.objects.events.presence.PresenceUpdateEvent`]]
296
        Presences of the members in the guild,
297
        will only include non-offline members if the size is greater
298
        than large threshold
299
    stage_instances: APINullable[List[:class:`~pincer.objects.guild.stage.StageInstance`]]
300
        Stage instances in the guild
301
    stickers: Optional[List[:class:`~pincer.objects.message.sticker.Sticker`]]
302
        Custom guild stickers
303
    region: APINullable[Optional[:class:`str`]]
304
        Voice region id for the guild (deprecated)
305
    threads: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
306
        All active threads in the guild that current user
307
        has permission to view
308
    unavailable: APINullable[:class:`bool`]
309
        True if this guild is unavailable due to an outage
310
    voice_states: APINullable[List[:class:`~pincer.objects.user.voice_state.VoiceState`]]
311
        States of members currently in voice channels;
312
        lacks the guild_id key
313
    widget_enabled: APINullable[:class:`bool`]
314
        True if the server widget is enabled
315
    widget_channel_id: APINullable[Optional[:class:`~pincer.utils.snowflake.Snowflake`]]
316
        The channel id that the widget will generate an invite to,
317
        or null if set to no invite
318
    welcome_screen: APINullable[:class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`]
319
        The welcome screen of a Community guild, shown to new members,
320
        returned in an Invite's guild object
321
    """
322
    # noqa: E501
323
    afk_timeout: int
324
    default_message_notifications: DefaultMessageNotificationLevel
325
    emojis: List[Emoji]
326
    explicit_content_filter: ExplicitContentFilterLevel
327
    features: List[GuildFeature]
328
    id: Snowflake
329
    mfa_level: MFALevel
330
    name: str
331
    nsfw_level: GuildNSFWLevel
332
    owner_id: Snowflake
333
    preferred_locale: str
334
    premium_tier: PremiumTier
335
    roles: List[Role]
336
    system_channel_flags: SystemChannelFlags
337
    verification_level: VerificationLevel
338
339
    guild_scheduled_events: APINullable[List] = MISSING
340
    lazy: APINullable[bool] = MISSING
341
    premium_progress_bar_enabled: APINullable[bool] = MISSING
342
    guild_hashes: APINullable[Dict] = MISSING
343
    afk_channel_id: APINullable[Snowflake] = MISSING
344
    application_id: APINullable[Snowflake] = MISSING
345
    embedded_activities: APINullable[List] = MISSING
346
    banner: APINullable[str] = MISSING
347
    description: APINullable[str] = MISSING
348
    discovery_splash: APINullable[str] = MISSING
349
    icon: APINullable[str] = MISSING
350
    public_updates_channel_id: APINullable[Snowflake] = MISSING
351
    rules_channel_id: APINullable[Snowflake] = MISSING
352
    splash: APINullable[str] = MISSING
353
    system_channel_id: APINullable[Snowflake] = MISSING
354
    vanity_url_code: APINullable[str] = MISSING
355
356
    application_command_counts: APINullable[Dict] = MISSING
357
    application_command_count: APINullable[int] = MISSING
358
    approximate_member_count: APINullable[int] = MISSING
359
    approximate_presence_count: APINullable[int] = MISSING
360
    channels: APINullable[List[Channel]] = field(default_factory=list)
361
    # 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...
362
    hub_type: APINullable[Any] = MISSING
363
    icon_hash: APINullable[Optional[str]] = MISSING
364
    joined_at: APINullable[Timestamp] = MISSING
365
    large: APINullable[bool] = MISSING
366
    max_members: APINullable[int] = MISSING
367
    max_presences: APINullable[Optional[int]] = MISSING
368
    max_video_channel_users: APINullable[int] = MISSING
369
    members: APINullable[List[GuildMember]] = MISSING
370
    member_count: APINullable[bool] = MISSING
371
    nsfw: APINullable[bool] = MISSING
372
    # Note: This is missing from discord's docs but in the api
373
    owner: APINullable[bool] = MISSING
374
    permissions: APINullable[str] = MISSING
375
    premium_subscription_count: APINullable[int] = MISSING
376
    presences: APINullable[List[PresenceUpdateEvent]] = MISSING
377
    stage_instances: APINullable[List[StageInstance]] = MISSING
378
    stickers: APINullable[List[Sticker]] = MISSING
379
    region: APINullable[Optional[str]] = MISSING
380
    threads: APINullable[List[Channel]] = MISSING
381
    # Guilds are considered available unless otherwise specified
382
    unavailable: APINullable[bool] = False
383
    voice_states: APINullable[List[VoiceState]] = MISSING
384
    widget_enabled: APINullable[bool] = MISSING
385
    widget_channel_id: APINullable[Optional[Snowflake]] = MISSING
386
    welcome_screen: APINullable[WelcomeScreen] = MISSING
387
388
    @classmethod
389
    async def from_id(cls, client: Client, _id: Union[int, Snowflake]) -> Guild:
390
        """
391
        Parameters
392
        ----------
393
        client : `~pincer.Client`
394
            Client object to use the http gateway from.
395
        _id : :class: `pincer.utils.snowflake.Snowflake`
396
            Guild ID.
397
        Returns
398
        -------
399
        :class: `~pincer.objects.guild.guild.Guild`
400
            The new guild object.
401
        """
402
        data = await client.http.get(f"/guilds/{_id}")
403
        channel_data = await client.http.get(f"/guilds/{_id}/channels")
404
405
        data["channels"]: List[Channel] = [
406
            Channel.from_dict({**i, "_client": client, "_http": client.http})
407
            for i in (channel_data or [])
408
        ]
409
410
        return Guild.from_dict(construct_client_dict(client, data))
411
412
    async def get_member(self, _id: int) -> GuildMember:
413
        """|coro|
414
        Fetches a GuildMember from its identifier
415
        Parameters
416
        ----------
417
        _id:
418
            The id of the guild member which should be fetched from the Discord
419
            gateway.
420
        Returns
421
        -------
422
        :class:`~pincer.objects.guild.member.GuildMember`
423
            A GuildMember object.
424
        """
425
        return await GuildMember.from_id(self._client, self.id, _id)
426
427
    @overload
428
    async def modify_member(
429
            self, *,
430
            _id: int,
431
            nick: Optional[str] = None,
432
            roles: Optional[List[Snowflake]] = None,
433
            mute: Optional[bool] = None,
434
            deaf: Optional[bool] = None,
435
            channel_id: Optional[Snowflake] = None
436
    ) -> GuildMember:
437
        """|coro|
438
        Modifies a member in the guild from its identifier and based on the
439
        keyword arguments provided.
440
        Parameters
441
        ----------
442
        _id : int
443
            Id of the member to modify
444
        nick : Optional[:class:`str`]
445
            New nickname for the member |default| :data:`None`
446
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake]]
447
            New roles for the member |default| :data:`None`
448
        mute : Optional[:class:`bool`]
449
            Whether the member is muted |default| :data:`None`
450
        deaf : Optional[:class:`bool`]
451
            Whether the member is deafened |default| :data:`None`
452
        channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake]
453
            Voice channel id to move to |default| :data:`None`
454
        Returns
455
        -------
456
        :class:`~pincer.objects.guild.member.GuildMember`
457
            The new member object.
458
        """
459
        ...
460
461
    async def modify_member(self, _id: int, **kwargs) -> GuildMember:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
462
        data = await self._http.patch(
463
            f"guilds/{self.id}/members/{_id}",
464
            data=kwargs
465
        )
466
        return GuildMember.from_dict(construct_client_dict(self._client, data))
467
468
    async def ban(
469
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
470
        member_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
471
        reason: str = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
472
        delete_message_days: int = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
473
    ):
474
        """
475
        Parameters
476
        ----------
477
        member_id : :class:`int`
478
            ID of the guild member to ban.
479
        reason : Optional[:class:`str`]
480
            Reason for the kick.
481
        delete_message_days : Optional[:class:`int`]
482
            Number of days to delete messages for (0-7)
483
        """
484
        headers = {}
485
486
        if reason is not None:
487
            headers["X-Audit-Log-Reason"] = reason
488
489
        data = {}
490
491
        if delete_message_days is not None:
492
            data["delete_message_days"] = delete_message_days
493
494
        await self._http.put(
495
            f"/guilds/{self.id}/bans/{member_id}",
496
            data=data,
497
            headers=headers
498
        )
499
500
    async def kick(self, member_id: int, reason: Optional[str] = None):
501
        """|coro|
502
        Kicks a guild member.
503
        Parameters
504
        ----------
505
        member_id : :class:`int`
506
            ID of the guild member to kick.
507
        reason : Optional[:class:`str`]
508
            Reason for the kick.
509
        """
510
511
        headers = {}
512
513
        if reason is not None:
514
            headers["X-Audit-Log-Reason"] = reason
515
516
        await self._http.delete(
517
            f"/guilds/{self.id}/members/{member_id}",
518
            header=headers
519
        )
520
521
    async def get_roles(self):
522
        """|coro|
523
        Fetches all the roles in the guild.
524
525
        Returns
526
        -------
527
        List[:class:`~pincer.objects.guild.role.Role`]
528
            A list of Role objects.
529
        """
530
        data = await self._http.get(f"guilds/{self.id}/roles")
531
        return [Role.from_dict(construct_client_dict(self._client, i)) for i in data]
532
533
    @overload
534
    async def create_role(
535
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
536
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
537
        name: Optional[str] = "new role",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
538
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
539
        color: Optional[int] = 0,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
540
        hoist: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
541
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
542
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
543
        mentionable: Optional[bool] = False
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
544
    ) -> Role:
545
        """|coro|
546
        Creates a new role for the guild.
547
        Requires the `MANAGE_ROLES` permission.
548
549
        Parameters
550
        ----------
551
        name : Optional[:class:`str`]
552
            name of the role |default| :data:`"new role"`
553
        permissions : Optional[:class:`str`]
554
            bitwise value of the enabled/disabled
555
            permissions |default| data:`None`
556
        color : Optional[:class:`int`]
557
            RGB color value |default| data:`0`
558
        hoist : Optional[:class:`bool`]
559
            whether the role should be displayed
560
            separately in the sidebar |default| data:`False`
561
        icon : Optional[:class:`str`]
562
            the role's icon image (if the guild has
563
            the `ROLE_ICONS` feature) |default| data:`None`
564
        unicode_emoji : Optional[:class:`str`]
565
            the role's unicode emoji as a standard emoji (if the guild
566
            has the `ROLE_ICONS` feature) |default| data:`None`
567
        mentionable : Optional[:class:`bool`]
568
            whether the role should be mentionable |default| data:`False`
569
570
        Returns
571
        -------
572
        :class:`~pincer.objects.guild.role.Role`
573
            The new role object.
574
        """
575
        ...
576
577
    async def create_role(self, **kwargs) -> Role:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
578
        return await self._http.post(f"guilds/{self.id}/roles", data=kwargs)
579
580
    async def edit_role_position(
581
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
582
        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...
583
        position: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
584
    ) -> List[Role]:
585
        """|coro|
586
        Edits the position of a role.
587
588
        Parameters
589
        ----------
590
        id : :class:`~pincer.utils.snowflake.Snowflake`
591
            The role ID
592
        position : Optional[:class:`int`]
593
            Sorting position of the role |default| data:`None`
594
595
        Returns
596
        -------
597
        List[:class:`~pincer.objects.guild.role.Role`]
598
            A list of all of the guild's role objects.
599
        """
600
        return [
601
            Role.from_dict(construct_client_dict(self._client, i))
602
            for i in await self._http.patch(
603
                f"guilds/{self.id}/roles",
604
                data={"id": id, "position": position}
605
            )
606
        ]
607
608
    @overload
609
    async def edit_role(
610
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
611
        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...
612
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
613
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
614
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
615
        color: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
616
        hoist: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
617
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
618
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
619
        mentionable: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
620
    ) -> Role:
621
        """|coro|
622
        Edits a role.
623
        Requires the `MANAGE_ROLES` permission.
624
625
        Parameters
626
        ----------
627
        id : :class:`~pincer.utils.snowflake.Snowflake`
628
            The role ID
629
        name : Optional[:class:`str`]
630
            Name of the role |default| data:`None`
631
        permissions : Optional[:class:`str`]
632
            Bitwise value of the enabled/disabled
633
            permissions |default| data:`None`
634
        color : Optional[:class:`int`]
635
            RGB color value |default| data:`None`
636
        hoist : Optional[:class:`bool`]
637
            Whether the role should be displayed
638
            separately in the sidebar |default| data:`None`
639
        icon : Optional[:class:`str`]
640
            The role's icon image (if the guild has
641
            the `ROLE_ICONS` feature) |default| data:`None`
642
        unicode_emoji : Optional[:class:`str`]
643
            The role's unicode emoji as a standard emoji (if the guild
644
            has the `ROLE_ICONS` feature) |default| data:`None`
645
        mentionable : Optional[:class:`bool`]
646
            Whether the role should be mentionable |default| data:`None`
647
648
        Returns
649
        -------
650
        :class:`~pincer.objects.guild.role.Role`
651
            The edited role object.
652
        """
653
        ...
654
655
    async def edit_role(self, id: Snowflake, **kwargs) -> Role:
0 ignored issues
show
introduced by
Missing function or method docstring
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
        return Role.from_dict(
657
            construct_client_dict(
658
                self._client,
659
                await self._http.patch(f"guilds/{self.id}/roles/{id}", data=kwargs)
660
            )
661
        )
662
663
    async def delete_role(self, id: Snowflake):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
664
        """|coro|
665
        Deletes a role.
666
        Requires the `MANAGE_ROLES` permission.
667
        Returns `204 No Content` on success.
668
669
        Parameters
670
        ----------
671
        id : :class:`~pincer.utils.snowflake.Snowflake`
672
            The role ID
673
        """
674
        await self._http.delete(f"guilds/{self.id}/roles/{id}")
675
676
    async def get_bans(self) -> List[Ban]:
677
        """|coro|
678
        Fetches all the bans in the guild.
679
680
        Returns
681
        -------
682
        List[:class:`~pincer.objects.guild.ban.Ban`]
683
            A list of Ban objects.
684
        """
685
        data = await self._http.get(f"guilds/{self.id}/bans")
686
        return [Ban.from_dict(construct_client_dict(self._client, i)) for i in data]
687
688
    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...
689
        """|coro|
690
        Fetches a ban from the guild.
691
        Returns `404 Not Found` if the user is not banned.
692
693
        Parameters
694
        ----------
695
        id : :class:`~pincer.utils.snowflake.Snowflake`
696
            The user ID
697
698
        Returns
699
        -------
700
        :class:`~pincer.objects.guild.ban.Ban`
701
            The Ban object.
702
        """
703
        return Ban.from_dict(
704
            construct_client_dict(
705
                self._client,
706
                await self._http.get(f"guilds/{self.id}/bans/{id}")
707
            )
708
        )
709
710
    async def unban(self, id: Snowflake):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
711
        """|coro|
712
        Unbans a user from the guild.
713
        Returns `204 No Content` on success.
714
715
        Parameters
716
        ----------
717
        id : :class:`~pincer.utils.snowflake.Snowflake`
718
            The user ID
719
        """
720
        await self._http.delete(f"guilds/{self.id}/bans/{id}")
721
722
    @overload
723
    async def edit(
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (20/15).
Loading history...
724
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
725
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
726
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
727
        region: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
728
        verification_level: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
729
        default_message_notifications: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
730
        explicit_content_filter: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
731
        afk_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
732
        afk_timeout: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
733
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
734
        owner_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
735
        splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
736
        discovery_splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
737
        banner: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
738
        system_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
739
        system_channel_flags: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
740
        rules_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
741
        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...
742
        preferred_locale: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
743
        features: Optional[List[GuildFeature]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
744
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
745
    ) -> Guild:
746
        """|coro|
747
        Modifies the guild
748
749
        Parameters
750
        ----------
751
        name : Optional[:class:`str`]
752
            Guild name |default| :data:`None`
753
        region : Optional[:class:`str`]
754
            Guild voice region ID |default| :data:`None`
755
        verification_level : Optional[:class:`int`]
756
            Verification level |default| :data:`None`
757
        default_message_notifications : Optional[:class:`int`]
758
            Default message notification level |default| :data:`None`
759
        explicit_content_filter : Optional[:class:`int`]
760
            Explicit content filter level |default| :data:`None`
761
        afk_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
762
            ID for AFK channel |default| :data:`None`
763
        afk_timeout : Optional[:class:`int`]
764
            AFK timeout in seconds |default| :data:`None`
765
        icon : Optional[:class:`str`]
766
            base64 1024x1024 png/jpeg/gif image for the guild icon
767
            (can be animated gif when the server
768
            has the `ANIMATED_ICON` feature) |default| :data:`None`
769
        owner_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
770
            User ID to transfer guild ownership to (must be owner) |default| :data:`None`
771
        splash : Optional[:class:`str`]
772
            base64 16:9 png/jpeg image for the guild splash (when the
773
            server has the `INVITE_SPLASH` feature) |default| :data:`None`
774
        discovery_splash : Optional[:class:`str`]
775
            base64 16:9 png/jpeg image for the guild discovery splash
776
            (when the server has the `DISCOVERABLE` feature) |default| :data:`None`
777
        banner : Optional[:class:`str`]
778
            base64 16:9 png/jpeg image for the guild banner (when the
779
            server has the `BANNER` feature) |default| :data:`None`
780
        system_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
781
            The ID of the channel where guild notices such as welcome
782
            messages and boost events are posted |default| :data:`None`
783
        system_channel_flags : Optional[:class:`int`]
784
            System channel flags |default| :data:`None`
785
        rules_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
786
            The ID of the channel where Community guilds display rules
787
            and/or guidelines |default| :data:`None`
788
        public_updates_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
789
            The ID of the channel where admins and moderators of
790
            Community guilds receive notices from Discord |default| :data:`None`
791
        preferred_locale : Optional[:class:`str`]
792
            The preferred locale of a Community guild used in server
793
            discovery and notices from Discord; defaults to "en-US" |default| :data:`None`
794
        features : Optional[List[:class:`GuildFeature`]]
795
            Enabled guild features |default| :data:`None`
796
        description : Optional[:class:`str`]
797
            The description for the guild, if the guild is discoverable |default| :data:`None`
798
799
        Returns
800
        -------
801
        :class:`~pincer.objects.guild.Guild`
802
            The modified guild object.
803
        """
804
        ...
805
806
    async def edit(self, **kwargs) -> Guild:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
807
        g = await self._http.patch(f"guilds/{self.id}", data=kwargs)
808
        return Guild.from_dict(construct_client_dict(self._client, g))
809
810
    async def preview(self) -> GuildPreview:
811
        """|coro|
812
        Previews the guild.
813
814
        Returns
815
        -------
816
        :class:`~pincer.objects.guild.guild.GuildPreview`
817
            The guild preview object.
818
        """
819
        data = await self._http.get(f"guilds/{self.id}/preview")
820
        return GuildPreview.from_dict(data)
821
822
    async def delete(self):
823
        """|coro|
824
        Deletes the guild. Returns `204 No Content` on success.
825
        """
826
        await self._http.delete(f"guilds/{self.id}")
827
828
    @classmethod
829
    def from_dict(cls, data) -> Guild:
830
        """
831
        Parameters
832
        ----------
833
        data : :class:`Dict`
834
            Guild data received from the discord API.
835
        Returns
836
        -------
837
        :class:`~pincer.objects.guild.guild.Guild`
838
            The new guild object.
839
        Raises
840
        :class:`~pincer.exceptions.UnavailableGuildError`
841
            The guild is unavailable due to a discord outage.
842
        """
843
        if data.get("unavailable", False):
844
            raise UnavailableGuildError(
845
                f"Guild \"{data['id']}\" is unavailable due to a discord"
846
                " outage."
847
            )
848
849
        return super().from_dict(data)
850
851
852
@dataclass
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
853
class UnavailableGuild(APIObject):
854
    id: Snowflake
855
    unavailable: bool = True
856