Passed
Pull Request — main (#292)
by Yohann
02:20 queued 10s
created

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

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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