Passed
Pull Request — main (#292)
by
unknown
01:51
created

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

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
coding-style introduced by
Too many lines in module (1697/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, Generator
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.emoji import Emoji
0 ignored issues
show
Unused Code introduced by
The import Emoji was already done on line 12. You should be able to
remove this line.
Loading history...
38
    from ..message.sticker import Sticker, StickerPack
39
    from ..user.voice_state import VoiceState
40
    from ...client import Client
41
    from ...utils.timestamp import Timestamp
42
    from ...utils.types import APINullable, JSONSerializable
43
    from ...utils.snowflake import Snowflake
44
45
46
class PremiumTier(IntEnum):
47
    """Represents the boost tier of a guild.
48
    Attributes
49
    ----------
50
    NONE:
51
        Guild has not unlocked any Server Boost perks.
52
    TIER_1:
53
        Guild has unlocked Server Boost level 1 perks.
54
    TIER_2:
55
        Guild has unlocked Server Boost level 2 perks.
56
    TIER_3:
57
        Guild has unlocked Server Boost level 3 perks.
58
    """
59
60
    NONE = 0
61
    TIER_1 = 1
62
    TIER_2 = 2
63
    TIER_3 = 3
64
65
66
class GuildNSFWLevel(IntEnum):
67
    """Represents the NSFW level of a guild.
68
    Attributes
69
    ----------
70
    DEFAULT:
71
        Default NSFW level.
72
    EXPLICIT:
73
        Explicit NSFW level.
74
    SAFE:
75
        SAFE NSFW level.
76
    AGE_RESTRICTED:
77
        Age restricted NSFW level.
78
    """
79
80
    DEFAULT = 0
81
    EXPLICIT = 1
82
    SAFE = 2
83
    AGE_RESTRICTED = 3
84
85
86
class ExplicitContentFilterLevel(IntEnum):
87
    """Represents the filter content level of a guild.
88
    Attributes
89
    ----------
90
    DISABLED:
91
        Media content will not be scanned.
92
    MEMBERS_WITHOUT_ROLES:
93
        Media content sent by members without roles will be scanned.
94
    ALL_MEMBERS:
95
        Media content sent by all members will be scanned.
96
    """
97
98
    DISABLED = 0
99
    MEMBERS_WITHOUT_ROLES = 1
100
    ALL_MEMBERS = 2
101
102
103
class MFALevel(IntEnum):
104
    """Represents the multi factor authentication level of a guild.
105
    Attributes
106
    ----------
107
    NONE:
108
        Guild has no MFA/2FA requirement for moderation actions.
109
    ELEVATED:
110
        Guild has a 2FA requirement for moderation actions
111
    """
112
113
    NONE = 0
114
    ELEVATED = 1
115
116
117
class VerificationLevel(IntEnum):
118
    """Represents the verification level of a guild.
119
    Attributes
120
    ----------
121
    NONE:
122
        Unrestricted.
123
    LOW:
124
        Must have verified email on account.
125
    MEDIUM:
126
        Must be registered on Discord for longer than 5 minutes.
127
    HIGH:
128
        Must be a member of the server for longer than 10 minutes.
129
    VERY_HIGH:
130
        Must have a verified phone number.
131
    """
132
133
    NONE = 0
134
    LOW = 1
135
    MEDIUM = 2
136
    HIGH = 3
137
    VERY_HIGH = 4
138
139
140
class DefaultMessageNotificationLevel(IntEnum):
141
    """Represents the default message notification level of a guild.
142
    Attributes
143
    ----------
144
    ALL_MESSAGES:
145
        Members will receive notifications for all messages by default.
146
    ONLY_MENTIONS:
147
        Members will receive notifications only for messages that @mention them by default.
148
    """
149
150
    # noqa: E501
151
    ALL_MESSAGES = 0
152
    ONLY_MENTIONS = 1
153
154
155
class SystemChannelFlags(IntEnum):
156
    """Represents the system channel flags of a guild.
157
    Attributes
158
    ----------
159
    SUPPRESS_JOIN_NOTIFICATIONS:
160
        Suppress member join notifications.
161
    SUPPRESS_PREMIUM_SUBSCRIPTIONS:
162
        Suppress server boost notifications.
163
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS:
164
        Suppress server setup tips.
165
    SUPPRESS_JOIN_NOTIFICATION_REPLIES:
166
        Hide member join sticker reply buttons
167
    """
168
169
    SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0
170
    SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
171
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS = 1 << 2
172
    SUPPRESS_JOIN_NOTIFICATION_REPLIES = 1 << 3
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 (49/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,
453
            *,
454
            _id: int,
455
            nick: Optional[str] = None,
456
            roles: Optional[List[Snowflake]] = None,
457
            mute: Optional[bool] = None,
458
            deaf: Optional[bool] = None,
459
            channel_id: Optional[Snowflake] = None,
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,
493
            member_id: int,
494
            reason: str = None,
495
            delete_message_days: int = None
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,
560
            reason: Optional[str] = None,
561
            *,
562
            name: Optional[str] = "new role",
563
            permissions: Optional[str] = None,
564
            color: Optional[int] = 0,
565
            hoist: Optional[bool] = False,
566
            icon: Optional[str] = None,
567
            unicode_emoji: Optional[str] = None,
568
            mentionable: Optional[bool] = False,
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,
607
            reason: Optional[str] = None,
608
            **kwargs
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,
623
            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...
624
            reason: Optional[str] = None,
625
            position: Optional[int] = None
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,
655
            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...
656
            reason: Optional[str] = None,
657
            *,
658
            name: Optional[str] = None,
659
            permissions: Optional[str] = None,
660
            color: Optional[int] = None,
661
            hoist: Optional[bool] = None,
662
            icon: Optional[str] = None,
663
            unicode_emoji: Optional[str] = None,
664
            mentionable: Optional[bool] = None,
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,
704
            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...
705
            reason: Optional[str] = None,
706
            **kwargs
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,
789
            *,
790
            name: Optional[str] = None,
791
            region: Optional[str] = None,
792
            verification_level: Optional[int] = None,
793
            default_message_notifications: Optional[int] = None,
794
            explicit_content_filter: Optional[int] = None,
795
            afk_channel_id: Optional[Snowflake] = None,
796
            afk_timeout: Optional[int] = None,
797
            icon: Optional[str] = None,
798
            owner_id: Optional[Snowflake] = None,
799
            splash: Optional[str] = None,
800
            discovery_splash: Optional[str] = None,
801
            banner: Optional[str] = None,
802
            system_channel_id: Optional[Snowflake] = None,
803
            system_channel_flags: Optional[int] = None,
804
            rules_channel_id: Optional[Snowflake] = None,
805
            public_updates_channel_id: Optional[Snowflake] = None,
806
            preferred_locale: Optional[str] = None,
807
            features: Optional[List[GuildFeature]] = None,
808
            description: Optional[str] = None,
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,
894
            days: Optional[int] = 7,
895
            include_roles: Optional[str] = None
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,
921
            days: Optional[int] = 7,
922
            compute_prune_days: Optional[bool] = True,
923
            include_roles: Optional[List[Snowflake]] = None,
924
            reason: Optional[str] = None
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(
970
                construct_client_dict(self._client, voice_region_data)
971
            )
972
973
    async def get_invites(self) -> AsyncGenerator[Invite, None]:
974
        """|coro|
975
        Returns an async generator of invites for the guild.
976
        Requires the ``MANAGE_GUILD`` permission.
977
978
        Yields
979
        -------
980
        AsyncGenerator[:class:`~pincer.objects.invite.Invite`, :data:`None`]
981
            An async generator of invites.
982
        """
983
        data = await self._http.get(f"guilds/{self.id}/invites")
984
        for invite_data in data:
985
            yield Invite.from_dict(
986
                construct_client_dict(self._client, invite_data)
987
            )
988
989
    async def get_integrations(self) -> AsyncGenerator[Integration, None]:
990
        """|coro|
991
        Returns an async generator of integrations for the guild.
992
        Requires the ``MANAGE_GUILD`` permission.
993
994
        Yields
995
        -------
996
        AsyncGenerator[:class:`~pincer.objects.integration.Integration`, :data:`None`]
997
            An async generator of integrations.
998
        """
999
        data = await self._http.get(f"guilds/{self.id}/integrations")
1000
        for integration_data in data:
1001
            yield Integration.from_dict(
1002
                construct_client_dict(self._client, integration_data)
1003
            )
1004
1005
    async def delete_integration(
1006
            self,
1007
            integration: Integration,
1008
            reason: Optional[str] = None
1009
    ):
1010
        """|coro|
1011
        Deletes an integration.
1012
        Requires the ``MANAGE_GUILD`` permission.
1013
1014
        Parameters
1015
        ----------
1016
        integration : :class:`~pincer.objects.integration.Integration`
1017
            The integration to delete.
1018
        reason : Optional[:class:`str`]
1019
            Reason for the deletion |default| :data:`None`
1020
        """
1021
        await self._http.delete(
1022
            f"guilds/{self.id}/integrations/{integration.id}",
1023
            headers=remove_none({"X-Audit-Log-Reason": reason})
1024
        )
1025
1026
    async def get_widget_settings(self) -> GuildWidget:
1027
        """|coro|
1028
        Returns the guild widget settings.
1029
        Requires the ``MANAGE_GUILD`` permission.
1030
1031
        Returns
1032
        -------
1033
        :class:`~pincer.objects.guild.widget.GuildWidget`
1034
            The guild widget settings.
1035
        """
1036
        return GuildWidget.from_dict(
1037
            construct_client_dict(
1038
                self._client,
1039
                await self._http.get(f"guilds/{self.id}/widget")
1040
            )
1041
        )
1042
1043
    async def modify_widget(
1044
            self,
1045
            reason: Optional[str] = None,
1046
            **kwargs
1047
    ) -> GuildWidget:
1048
        """|coro|
1049
        Modifies the guild widget for the guild.
1050
        Requires the ``MANAGE_GUILD`` permission.
1051
1052
        Parameters
1053
        ----------
1054
        reason : Optional[:class:`str`]
1055
            Reason for the modification |default| :data:`None`
1056
        \\*\\*kwargs
1057
            The widget settings to modify
1058
1059
        Returns
1060
        -------
1061
        :class:`~pincer.objects.guild.widget.GuildWidget`
1062
            The updated GuildWidget object
1063
        """
1064
        data = await self._http.patch(
1065
            f"guilds/{self.id}/widget",
1066
            data=kwargs,
1067
            headers=remove_none({"X-Audit-Log-Reason": reason})
1068
        )
1069
        return GuildWidget.from_dict(construct_client_dict(self._client, data))
1070
1071
    async def get_widget(self) -> Dict[str, JSONSerializable]:
1072
        """|coro|
1073
        Returns the widget for the guild
1074
        """
1075
        return await self._http.get(f"guilds/{self.id}/widget.json")
1076
1077
    @property
1078
    async def vanity_url(self) -> Invite:
1079
        """|coro|
1080
        Returns the Vanity URL for the guild.
1081
        Requires the ``MANAGE_GUILD`` permission.
1082
        ``code`` will be null if a vanity URL has not been set.
1083
1084
        Returns
1085
        -------
1086
        :class:`~pincer.objects.guild.invite.Invite`
1087
            The vanity url for the guild.
1088
        """
1089
        data = await self._http.get(f"guilds/{self.id}/vanity-url")
1090
        return Invite.from_dict(construct_client_dict(self._client, data))
1091
1092
    async def get_widget_image(
1093
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1094
        style: Optional[str] = "shield"
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1095
    ) -> str:  # TODO Replace str with ImageURL object
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
1096
        """|coro|
1097
        Returns a PNG image widget for the guild.
1098
        Requires no permissions or authentication.
1099
1100
        Widget Style Options
1101
        -------------------
1102
        * [``shield``](https://discord.com/api/guilds/81384788765712384/widget.png?style=shield)
1103
          shield style widget with Discord icon and guild members online count
1104
        * [``banner1``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner1)
1105
          large image with guild icon, name and online count.
1106
          "POWERED BY DISCORD" as the footer of the widget
1107
        * [``banner2``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner2)
1108
          smaller widget style with guild icon, name and online count.
1109
          Split on the right with Discord logo
1110
        * [``banner3``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner3)
1111
          large image with guild icon, name and online count.
1112
          In the footer, Discord logo on the
1113
          left and "Chat Now" on the right
1114
        * [``banner4``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner4)
1115
          large Discord logo at the top of the widget.
1116
          Guild icon, name and online count in the middle portion
1117
          of the widget and a "JOIN MY SERVER" button at the bottom
1118
1119
        Parameters
1120
        ----------
1121
        style : Optional[:class:`str`]
1122
            Style of the widget image returned |default| :data:`"shield"`
1123
1124
        Returns
1125
        -------
1126
        :class:`str`
1127
            A PNG image of the guild widget.
1128
        """
1129
        return await self._http.get(f"guilds/{self.id}/widget.png?{style=!s}")
1130
1131
    async def get_welcome_screen(self) -> WelcomeScreen:
1132
        """Returns the welcome screen for the guild.
1133
1134
        Returns
1135
        -------
1136
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1137
            The welcome screen for the guild.
1138
        """
1139
        data = await self._http.get(f"guilds/{self.id}/welcome-screen")
1140
        return WelcomeScreen.from_dict(
1141
            construct_client_dict(self._client, data)
1142
        )
1143
1144
    async def modify_welcome_screen(
1145
            self,
1146
            enabled: Optional[bool] = None,
1147
            welcome_channels: Optional[List[WelcomeScreenChannel]] = None,
1148
            description: Optional[str] = None,
1149
            reason: Optional[str] = None
1150
    ) -> WelcomeScreen:
1151
        """|coro|
1152
        Modifies the guild's Welcome Screen.
1153
        Requires the ``MANAGE_GUILD`` permission.
1154
1155
        Parameters
1156
        ----------
1157
        enabled : Optional[:class:`bool`]
1158
            Whether the welcome screen is enabled |default| :data:`None`
1159
        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...
1160
            Channels linked in the welcome screen and
1161
            their display options |default| :data:`None`
1162
        description : Optional[:class:`str`]
1163
            The server description to show
1164
            in the welcome screen |default| :data:`None`
1165
        reason : Optional[:class:`str`]
1166
            Reason for the modification |default| :data:`None`
1167
1168
        Returns
1169
        -------
1170
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1171
            The updated WelcomeScreen object
1172
        """
1173
        data = await self._http.patch(
1174
            f"guilds/{self.id}/welcome-screen",
1175
            data={
1176
                "enabled": enabled,
1177
                "welcome_channels": welcome_channels,
1178
                "description": description
1179
            },
1180
            headers=remove_none({"X-Audit-Log-Reason": reason})
1181
        )
1182
        return WelcomeScreen.from_dict(
1183
            construct_client_dict(self._client, data)
1184
        )
1185
1186
    async def modify_current_user_voice_state(
1187
            self,
1188
            channel_id: Snowflake,
1189
            suppress: Optional[bool] = None,
1190
            request_to_speak_timestamp: Optional[Timestamp] = None
1191
    ):
1192
        """|coro|
1193
        Updates the current user's voice state.
1194
1195
        There are currently several caveats for this endpoint:
1196
        * ``channel_id`` must currently point to a stage channel
1197
        * current user must already have joined ``channel_id``
1198
        * You must have the ``MUTE_MEMBERS`` permission to
1199
          unsuppress yourself. You can always suppress yourself.
1200
        * You must have the ``REQUEST_TO_SPEAK`` permission to request
1201
          to speak. You can always clear your own request to speak.
1202
        * You are able to set ``request_to_speak_timestamp`` to any
1203
          present or future time.
1204
1205
        Parameters
1206
        ----------
1207
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1208
            The ID of the channel the user is currently in
1209
        suppress : Optional[:class:`bool`]
1210
            Toggles the user's suppress state |default| :data:`None`
1211
        request_to_speak_timestamp : Optional[:class:`~pincer.utils.timestamp.Timestamp`]
1212
            Sets the user's request to speak
1213
        """
1214
        await self._http.patch(
1215
            f"guilds/{self.id}/voice-states/@me",
1216
            data={
1217
                "channel_id": channel_id,
1218
                "suppress": suppress,
1219
                "request_to_speak_timestamp": request_to_speak_timestamp
1220
            }
1221
        )
1222
1223
    async def modify_user_voice_state(
1224
            self,
1225
            user: User,
1226
            channel_id: Snowflake,
1227
            suppress: Optional[bool] = None
1228
    ):
1229
        """|coro|
1230
        Updates another user's voice state.
1231
1232
        There are currently several caveats for this endpoint:
1233
        * ``channel_id`` must currently point to a stage channel
1234
        * User must already have joined ``channel_id``
1235
        * You must have the ``MUTE_MEMBERS`` permission.
1236
          (Since suppression is the only thing that is available currently.)
1237
        * When unsuppressed, non-bot users will have their
1238
          ``request_to_speak_timestamp`` set to the current time.
1239
          Bot users will not.
1240
        * When suppressed, the user will have their
1241
          ``request_to_speak_timestamp`` removed.
1242
1243
        Parameters
1244
        ----------
1245
        user : :class:`~pincer.objects.guild.member.Member`
1246
            The user to update
1247
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1248
            The ID of the channel the user is currently in
1249
        suppress : Optional[:class:`bool`]
1250
            Toggles the user's suppress state |default| :data:`None`
1251
        """
1252
        await self._http.patch(
1253
            f"guilds/{self.id}/voice-states/{user.id}",
1254
            data={
1255
                "channel_id": channel_id,
1256
                "suppress": suppress
1257
            }
1258
        )
1259
1260
    async def get_audit_log(self) -> AuditLog:
1261
        """|coro|
1262
        Returns an audit log object for the guild.
1263
        Requires the ``VIEW_AUDIT_LOG`` permission.
1264
1265
        Returns
1266
        -------
1267
        :class:`~pincer.objects.guild.audit_log.AuditLog`
1268
            The audit log object for the guild.
1269
        """
1270
        return AuditLog.from_dict(
1271
            construct_client_dict(
1272
                self._client,
1273
                await self._http.get(f"guilds/{self.id}/audit-logs")
1274
            )
1275
        )
1276
1277
    async def get_emojis(self) -> AsyncGenerator[Emoji, None]:
1278
        """|coro|
1279
        Returns an async generator of the emojis in the guild.
1280
1281
        Yields
1282
        ------
1283
        :class:`~pincer.objects.guild.emoji.Emoji`
1284
            The emoji object.
1285
        """
1286
        data = await self._http.get(f"guilds/{self.id}/emojis")
1287
        for emoji_data in data:
1288
            yield Emoji.from_dict(
1289
                construct_client_dict(self._client, emoji_data)
1290
            )
1291
1292
    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...
1293
        """|coro|
1294
        Returns an emoji object for the given ID.
1295
1296
        Parameters
1297
        ----------
1298
        id : :class:`~pincer.utils.snowflake.Snowflake`
1299
            The ID of the emoji
1300
1301
        Returns
1302
        -------
1303
        :class:`~pincer.objects.guild.emoji.Emoji`
1304
            The emoji object.
1305
        """
1306
        return Emoji.from_dict(
1307
            construct_client_dict(
1308
                self._client,
1309
                await self._http.get(f"guilds/{self.id}/emojis/{id}")
1310
            )
1311
        )
1312
1313
    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...
1314
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1315
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1316
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1317
        image: File,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1318
        roles: List[Snowflake] = [],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1319
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1320
    ) -> Emoji:
1321
        """|coro|
1322
        Creates a new emoji for the guild.
1323
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1324
1325
        Emojis and animated emojis have a maximum file size of 256kb.
1326
        Attempting to upload an emoji larger than this limit will fail.
1327
1328
        Parameters
1329
        ----------
1330
        name : :class:`str`
1331
            Name of the emoji
1332
        image : :class:`~pincer.objects.message.file.File`
1333
            The File for the 128x128 emoji image data
1334
        roles : List[:class:`~pincer.utils.snowflake.Snowflake`]
1335
            Roles allowed to use this emoji |default| :data:`[]`
1336
        reason : Optional[:class:`str`]
1337
            The reason for creating the emoji |default| :data:`None`
1338
1339
        Returns
1340
        -------
1341
        :class:`~pincer.objects.guild.emoji.Emoji`
1342
            The newly created emoji object.
1343
        """
1344
        data = await self._http.post(
1345
            f"guilds/{self.id}/emojis",
1346
            data={
1347
                "name": name,
1348
                "image": image.uri,
1349
                "roles": roles
1350
            },
1351
            headers=remove_none({"X-Audit-Log-Reason": reason})
1352
        )
1353
        return Emoji.from_dict(
1354
            construct_client_dict(self._client, data)
1355
        )
1356
1357
    async def edit_emoji(
1358
            self,
1359
            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...
1360
            *,
1361
            name: Optional[str] = None,
1362
            roles: Optional[List[Snowflake]] = None,
1363
            reason: Optional[str] = None
1364
    ) -> Emoji:
1365
        """|coro|
1366
        Modifies the given emoji.
1367
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1368
1369
        Parameters
1370
        ----------
1371
        id : :class:`~pincer.utils.snowflake.Snowflake`
1372
            The ID of the emoji
1373
        name : Optional[:class:`str`]
1374
            Name of the emoji |default| :data:`None`
1375
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1376
            Roles allowed to use this emoji |default| :data:`None`
1377
        reason : Optional[:class:`str`]
1378
            The reason for editing the emoji |default| :data:`None`
1379
1380
        Returns
1381
        -------
1382
        :class:`~pincer.objects.guild.emoji.Emoji`
1383
            The modified emoji object.
1384
        """
1385
        data = await self._http.patch(
1386
            f"guilds/{self.id}/emojis/{id}",
1387
            data={
1388
                "name": name,
1389
                "roles": roles
1390
            },
1391
            headers=remove_none({"X-Audit-Log-Reason": reason})
1392
        )
1393
        return Emoji.from_dict(
1394
            construct_client_dict(self._client, data)
1395
        )
1396
1397
    async def delete_emoji(
1398
            self,
1399
            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...
1400
            *,
1401
            reason: Optional[str] = None
1402
    ):
1403
        """|coro|
1404
        Deletes the given emoji.
1405
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1406
1407
        Parameters
1408
        ----------
1409
        id : :class:`~pincer.utils.snowflake.Snowflake`
1410
            The ID of the emoji
1411
        reason : Optional[:class:`str`]
1412
            The reason for deleting the emoji |default| :data:`None`
1413
        """
1414
        await self._http.delete(
1415
            f"guilds/{self.id}/emojis/{id}",
1416
            headers=remove_none({"X-Audit-Log-Reason": reason})
1417
        )
1418
1419
    async def get_templates(self) -> AsyncGenerator[GuildTemplate, None]:
1420
        """|coro|
1421
        Returns an async generator of the guild templates.
1422
1423
        Yields
1424
        -------
1425
        AsyncGenerator[:class:`~pincer.objects.guild.template.GuildTemplate`, :data:`None`]
1426
            The guild template object.
1427
        """
1428
        data = await self._http.get(f"guilds/{self.id}/templates")
1429
        for template_data in data:
1430
            yield GuildTemplate.from_dict(
1431
                construct_client_dict(self._client, template_data)
1432
            )
1433
1434
    async def create_template(
1435
            self,
1436
            name: str,
1437
            description: Optional[str] = None
1438
    ) -> GuildTemplate:
1439
        """|coro|
1440
        Creates a new template for the guild.
1441
        Requires the ``MANAGE_GUILD`` permission.
1442
1443
        Parameters
1444
        ----------
1445
        name : :class:`str`
1446
            Name of the template (1-100 characters)
1447
        description : Optional[:class:`str`]
1448
            Description of the template
1449
            (0-120 characters) |default| :data:`None`
1450
        Returns
1451
        -------
1452
        :class:`~pincer.objects.guild.template.GuildTemplate`
1453
            The newly created template object.
1454
        """
1455
        data = await self._http.post(
1456
            f"guilds/{self.id}/templates",
1457
            data={
1458
                "name": name,
1459
                "description": description
1460
            }
1461
        )
1462
        return GuildTemplate.from_dict(
1463
            construct_client_dict(self._client, data)
1464
        )
1465
1466
    async def sync_template(
1467
            self,
1468
            template: GuildTemplate
1469
    ) -> GuildTemplate:
1470
        """|coro|
1471
        Syncs the given template.
1472
        Requires the ``MANAGE_GUILD`` permission.
1473
1474
        Parameters
1475
        ----------
1476
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1477
            The template to sync
1478
1479
        Returns
1480
        -------
1481
        :class:`~pincer.objects.guild.template.GuildTemplate`
1482
            The synced template object.
1483
        """
1484
        data = await self._http.put(
1485
            f"guilds/{self.id}/templates/{template.code}"
1486
        )
1487
        return GuildTemplate.from_dict(
1488
            construct_client_dict(self._client, data)
1489
        )
1490
1491
    async def edit_template(
1492
            self,
1493
            template: GuildTemplate,
1494
            *,
1495
            name: Optional[str] = None,
1496
            description: Optional[str] = None
1497
    ) -> GuildTemplate:
1498
        """|coro|
1499
        Modifies the template's metadata.
1500
        Requires the ``MANAGE_GUILD`` permission.
1501
1502
        Parameters
1503
        ----------
1504
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1505
            The template to edit
1506
        name : Optional[:class:`str`]
1507
            Name of the template (1-100 characters)
1508
            |default| :data:`None`
1509
        description : Optional[:class:`str`]
1510
            Description of the template (0-120 characters)
1511
            |default| :data:`None`
1512
1513
        Returns
1514
        -------
1515
        :class:`~pincer.objects.guild.template.GuildTemplate`
1516
            The edited template object.
1517
        """
1518
        data = await self._http.patch(
1519
            f"guilds/{self.id}/templates/{template.code}",
1520
            data={
1521
                "name": name,
1522
                "description": description
1523
            }
1524
        )
1525
        return GuildTemplate.from_dict(
1526
            construct_client_dict(self._client, data)
1527
        )
1528
1529
    async def delete_template(
1530
            self,
1531
            template: GuildTemplate
1532
    ) -> GuildTemplate:
1533
        """|coro|
1534
        Deletes the given template.
1535
        Requires the ``MANAGE_GUILD`` permission.
1536
1537
        Parameters
1538
        ----------
1539
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1540
            The template to delete
1541
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1542
        Returns
1543
        -------
1544
        :class:`~pincer.objects.guild.template.GuildTemplate`
1545
            The deleted template object.
1546
        """
1547
        data = await self._http.delete(
1548
            f"guilds/{self.id}/templates/{template.code}"
1549
        )
1550
        return GuildTemplate.from_dict(
1551
            construct_client_dict(self._client, data)
1552
        )
1553
1554
    @classmethod
1555
    async def sticker_packs(cls) -> Generator[StickerPack, None, None]:
1556
        """|coro|
1557
        Returns the list of sticker packs available to Nitro subscribers.
1558
1559
        Yields
1560
        ------
1561
        :class:`~pincer.objects.message.sticker.StickerPack`
1562
            a sticker pack
1563
        """
1564
        packs = await cls._http.get("sticker-packs")
0 ignored issues
show
Bug introduced by
The Class Guild does not seem to have a member named _http.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
1565
        return (StickerPack.from_dict(pack) for pack in packs)
1566
1567
    async def list_stickers(self) -> Generator[Sticker, None, None]:
1568
        """|coro|
1569
        Returns an array of sticker objects for the current guild.
1570
        Includes ``user`` fields if the bot has the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1571
1572
        Yields
1573
        ------
1574
        :class:`~pincer.objects.message.sticker.Sticker`
1575
            a sticker for the current guild
1576
        """
1577
        return (
1578
            Sticker.from_dict(sticker)
1579
            for sticker in await self._http.get(f"guild/{self.id}/stickers")
1580
        )
1581
1582
    async def get_sticker(self, _id: Snowflake) -> Sticker:
1583
        """|coro|
1584
        Returns a sticker object for the current guild and sticker IDs.
1585
        Includes the ``user`` field if the bot has the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1586
1587
        Parameters
1588
        ----------
1589
        _id : int
1590
            id of the sticker
1591
1592
        Returns
1593
        -------
1594
        :class:`~pincer.objects.message.sticker.Sticker`
1595
            the sticker requested
1596
        """
1597
        sticker = await self._http.get(f"guilds/{self.id}/stickers/{_id}")
1598
        return Sticker.from_dict(sticker)
1599
1600
    async def create_sticker(
0 ignored issues
show
best-practice introduced by
Too many arguments (6/5)
Loading history...
1601
            self,
1602
            name: str,
1603
            tags: str,
1604
            file,
1605
            description: str = "",
1606
            reason: Optional[str] = None
1607
    ) -> Sticker:
1608
        """NOT IMPLEMENTED: DOES NOT WORK"""
1609
        raise NotImplementedError
1610
        # TODO: Fix this once File is fixed
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
1611
        # """|coro|
1612
        # Create a new sticker for the guild.
1613
        # Requires the ``MANAGE_EMOJIS_AND_STICKERS permission``.
1614
        #
1615
        # Parameters
1616
        # ----------
1617
        # name : str
1618
        #     name of the sticker (2-30 characters)
1619
        # tags : str
1620
        #     autocomplete/suggestion tags for the sticker (max 200 characters)
1621
        # file :
1622
        #     the sticker file to upload, must be a PNG, APNG, or Lottie JSON file, max 500 KB
1623
        # description : Optional[:class:`str`]
1624
        #     description of the sticker (empty or 2-100 characters) |default| :data:`""`
1625
        # reason : Optional[:class:`str`] |default| :data:`None`
1626
        #     reason for creating the sticker
1627
        #
1628
        # Returns
1629
        # -------
1630
        # :class:`~pincer.objects.message.sticker.Sticker`
1631
        #     the newly created sticker
1632
        # """
1633
        # sticker = await self._http.post(
1634
        #     f"guilds/{self.id}/stickers",
1635
        #     headers=remove_none({"X-Audit-Log-Reason": reason})
1636
        # )
1637
        #
1638
        # return Sticker.from_dict(sticker)
1639
1640
1641
    async def delete_sticker(self, _id: Snowflake) -> None:
1642
        """|coro|
1643
        Delete the given sticker.
1644
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1645
1646
        Parameters
1647
        ----------
1648
        _id: Snowflake
1649
            id of the sticker
1650
        """
1651
        await self._http.delete(f"guilds/{self.id}/stickers/{_id}")
1652
1653
    async def get_webhooks(self) -> AsyncGenerator[Webhook, None]:
1654
        """|coro|
1655
        Returns an async generator of the guild webhooks.
1656
1657
        Yields
1658
        -------
1659
        AsyncGenerator[:class:`~pincer.objects.guild.webhook.Webhook`, None]
1660
            The guild webhook object.
1661
        """
1662
        data = await self._http.get(f"guilds/{self.id}/webhooks")
1663
        for webhook_data in data:
1664
            yield Webhook.from_dict(
1665
                construct_client_dict(self._client, webhook_data)
1666
            )
1667
1668
1669
    @classmethod
1670
    def from_dict(cls, data) -> Guild:
1671
        """
1672
        Parameters
1673
        ----------
1674
        data : :class:`Dict`
1675
            Guild data received from the discord API.
1676
        Returns
1677
        -------
1678
        :class:`~pincer.objects.guild.guild.Guild`
1679
            The new guild object.
1680
        Raises
1681
        ------
1682
        :class:`~pincer.exceptions.UnavailableGuildError`
1683
            The guild is unavailable due to a discord outage.
1684
        """
1685
        if data.get("unavailable", False):
1686
            raise UnavailableGuildError(
1687
                f"Guild \"{data['id']}\" is unavailable due to a discord"
1688
                " outage."
1689
            )
1690
1691
        return super().from_dict(data)
1692
1693
1694
@dataclass(repr=False)
1695
class UnavailableGuild(APIObject):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
1696
    id: Snowflake
1697
    unavailable: bool = True
1698