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

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

Loading history...
1332
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1333
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1334
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1335
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1336
    ) -> Emoji:
1337
        """|coro|
1338
        Modifies the given emoji.
1339
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1340
1341
        Parameters
1342
        ----------
1343
        id : :class:`~pincer.utils.snowflake.Snowflake`
1344
            The ID of the emoji
1345
        name : Optional[:class:`str`]
1346
            Name of the emoji |default| :data:`None`
1347
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1348
            Roles allowed to use this emoji |default| :data:`None`
1349
        reason : Optional[:class:`str`]
1350
            The reason for editing the emoji |default| :data:`None`
1351
1352
        Returns
1353
        -------
1354
        :class:`~pincer.objects.guild.emoji.Emoji`
1355
            The modified emoji object.
1356
        """
1357
        data = await self._http.patch(
1358
            f"guilds/{self.id}/emojis/{id}",
1359
            data={"name": name, "roles": roles},
1360
            headers=remove_none({"X-Audit-Log-Reason": reason}),
1361
        )
1362
        return Emoji.from_dict(construct_client_dict(self._client, data))
1363
1364
    async def delete_emoji(
1365
        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...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1366
    ):
1367
        """|coro|
1368
        Deletes the given emoji.
1369
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1370
1371
        Parameters
1372
        ----------
1373
        id : :class:`~pincer.utils.snowflake.Snowflake`
1374
            The ID of the emoji
1375
        reason : Optional[:class:`str`]
1376
            The reason for deleting the emoji |default| :data:`None`
1377
        """
1378
        await self._http.delete(
1379
            f"guilds/{self.id}/emojis/{id}",
1380
            headers=remove_none({"X-Audit-Log-Reason": reason}),
1381
        )
1382
1383
    async def get_templates(self) -> AsyncGenerator[GuildTemplate, None]:
1384
        """|coro|
1385
        Returns an async generator of the guild templates.
1386
1387
        Yields
1388
        -------
1389
        AsyncGenerator[:class:`~pincer.objects.guild.template.GuildTemplate`, :data:`None`]
1390
            The guild template object.
1391
        """
1392
        data = await self._http.get(f"guilds/{self.id}/templates")
1393
        for template_data in data:
1394
            yield GuildTemplate.from_dict(
1395
                construct_client_dict(self._client, template_data)
1396
            )
1397
1398
    async def create_template(
1399
        self, name: str, description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1400
    ) -> GuildTemplate:
1401
        """|coro|
1402
        Creates a new template for the guild.
1403
        Requires the ``MANAGE_GUILD`` permission.
1404
1405
        Parameters
1406
        ----------
1407
        name : :class:`str`
1408
            Name of the template (1-100 characters)
1409
        description : Optional[:class:`str`]
1410
            Description of the template
1411
            (0-120 characters) |default| :data:`None`
1412
        Returns
1413
        -------
1414
        :class:`~pincer.objects.guild.template.GuildTemplate`
1415
            The newly created template object.
1416
        """
1417
        data = await self._http.post(
1418
            f"guilds/{self.id}/templates",
1419
            data={"name": name, "description": description},
1420
        )
1421
        return GuildTemplate.from_dict(
1422
            construct_client_dict(self._client, data)
1423
        )
1424
1425
    async def sync_template(self, template: GuildTemplate) -> GuildTemplate:
1426
        """|coro|
1427
        Syncs the given template.
1428
        Requires the ``MANAGE_GUILD`` permission.
1429
1430
        Parameters
1431
        ----------
1432
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1433
            The template to sync
1434
1435
        Returns
1436
        -------
1437
        :class:`~pincer.objects.guild.template.GuildTemplate`
1438
            The synced template object.
1439
        """
1440
        data = await self._http.put(
1441
            f"guilds/{self.id}/templates/{template.code}"
1442
        )
1443
        return GuildTemplate.from_dict(
1444
            construct_client_dict(self._client, data)
1445
        )
1446
1447
    async def edit_template(
1448
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1449
        template: GuildTemplate,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1450
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1451
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1452
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1453
    ) -> GuildTemplate:
1454
        """|coro|
1455
        Modifies the template's metadata.
1456
        Requires the ``MANAGE_GUILD`` permission.
1457
1458
        Parameters
1459
        ----------
1460
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1461
            The template to edit
1462
        name : Optional[:class:`str`]
1463
            Name of the template (1-100 characters)
1464
            |default| :data:`None`
1465
        description : Optional[:class:`str`]
1466
            Description of the template (0-120 characters)
1467
            |default| :data:`None`
1468
1469
        Returns
1470
        -------
1471
        :class:`~pincer.objects.guild.template.GuildTemplate`
1472
            The edited template object.
1473
        """
1474
        data = await self._http.patch(
1475
            f"guilds/{self.id}/templates/{template.code}",
1476
            data={"name": name, "description": description},
1477
        )
1478
        return GuildTemplate.from_dict(
1479
            construct_client_dict(self._client, data)
1480
        )
1481
1482
    async def delete_template(self, template: GuildTemplate) -> GuildTemplate:
1483
        """|coro|
1484
        Deletes the given template.
1485
        Requires the ``MANAGE_GUILD`` permission.
1486
1487
        Parameters
1488
        ----------
1489
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1490
            The template to delete
1491
1492
        Returns
1493
        -------
1494
        :class:`~pincer.objects.guild.template.GuildTemplate`
1495
            The deleted template object.
1496
        """
1497
        data = await self._http.delete(
1498
            f"guilds/{self.id}/templates/{template.code}"
1499
        )
1500
        return GuildTemplate.from_dict(
1501
            construct_client_dict(self._client, data)
1502
        )
1503
1504
    @classmethod
1505
    async def sticker_packs(cls) -> Generator[StickerPack, None, None]:
1506
        """|coro|
1507
        Returns the list of sticker packs available to Nitro subscribers.
1508
1509
        Yields
1510
        ------
1511
        :class:`~pincer.objects.message.sticker.StickerPack`
1512
            a sticker pack
1513
        """
1514
        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...
1515
        return (StickerPack.from_dict(pack) for pack in packs)
1516
1517
    async def list_stickers(self) -> Generator[Sticker, None, None]:
1518
        """|coro|
1519
        Returns an array of sticker objects for the current guild.
1520
        Includes ``user`` fields if the bot has the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1521
1522
        Yields
1523
        ------
1524
        :class:`~pincer.objects.message.sticker.Sticker`
1525
            a sticker for the current guild
1526
        """
1527
        return (
1528
            Sticker.from_dict(sticker)
1529
            for sticker in await self._http.get(f"guild/{self.id}/stickers")
1530
        )
1531
1532
    async def get_sticker(self, _id: Snowflake) -> Sticker:
1533
        """|coro|
1534
        Returns a sticker object for the current guild and sticker IDs.
1535
        Includes the ``user`` field if the bot has the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1536
1537
        Parameters
1538
        ----------
1539
        _id : int
1540
            id of the sticker
1541
1542
        Returns
1543
        -------
1544
        :class:`~pincer.objects.message.sticker.Sticker`
1545
            the sticker requested
1546
        """
1547
        sticker = await self._http.get(f"guilds/{self.id}/stickers/{_id}")
1548
        return Sticker.from_dict(sticker)
1549
1550
    async def create_sticker(
0 ignored issues
show
best-practice introduced by
Too many arguments (6/5)
Loading history...
1551
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1552
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1553
        tags: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1554
        file,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1555
        description: str = "",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1556
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1557
    ) -> Sticker:
1558
        """NOT IMPLEMENTED: DOES NOT WORK"""
1559
        raise NotImplementedError
1560
        # 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...
1561
        # """|coro|
1562
        # Create a new sticker for the guild.
1563
        # Requires the ``MANAGE_EMOJIS_AND_STICKERS permission``.
1564
        #
1565
        # Parameters
1566
        # ----------
1567
        # name : str
1568
        #     name of the sticker (2-30 characters)
1569
        # tags : str
1570
        #     autocomplete/suggestion tags for the sticker (max 200 characters)
1571
        # file :
1572
        #     the sticker file to upload, must be a PNG, APNG, or Lottie JSON file, max 500 KB
1573
        # description : Optional[:class:`str`]
1574
        #     description of the sticker (empty or 2-100 characters) |default| :data:`""`
1575
        # reason : Optional[:class:`str`] |default| :data:`None`
1576
        #     reason for creating the sticker
1577
        #
1578
        # Returns
1579
        # -------
1580
        # :class:`~pincer.objects.message.sticker.Sticker`
1581
        #     the newly created sticker
1582
        # """
1583
        # sticker = await self._http.post(
1584
        #     f"guilds/{self.id}/stickers",
1585
        #     headers=remove_none({"X-Audit-Log-Reason": reason})
1586
        # )
1587
        #
1588
        # return Sticker.from_dict(sticker)
1589
1590
    async def delete_sticker(self, _id: Snowflake):
1591
        """|coro|
1592
        Delete the given sticker.
1593
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1594
1595
        Parameters
1596
        ----------
1597
        _id: Snowflake
1598
            id of the sticker
1599
        """
1600
        await self._http.delete(f"guilds/{self.id}/stickers/{_id}")
1601
1602
    async def get_webhooks(self) -> AsyncGenerator[Webhook, None]:
1603
        """|coro|
1604
        Returns an async generator of the guild webhooks.
1605
1606
        Yields
1607
        -------
1608
        AsyncGenerator[:class:`~pincer.objects.guild.webhook.Webhook`, None]
1609
            The guild webhook object.
1610
        """
1611
        data = await self._http.get(f"guilds/{self.id}/webhooks")
1612
        for webhook_data in data:
1613
            yield Webhook.from_dict(
1614
                construct_client_dict(self._client, webhook_data)
1615
            )
1616
1617
    @classmethod
1618
    def from_dict(cls, data) -> Guild:
1619
        """
1620
        Parameters
1621
        ----------
1622
        data : :class:`Dict`
1623
            Guild data received from the discord API.
1624
        Returns
1625
        -------
1626
        :class:`~pincer.objects.guild.guild.Guild`
1627
            The new guild object.
1628
        Raises
1629
        ------
1630
        :class:`~pincer.exceptions.UnavailableGuildError`
1631
            The guild is unavailable due to a discord outage.
1632
        """
1633
        if data.get("unavailable", False):
1634
            raise UnavailableGuildError(
1635
                f"Guild \"{data['id']}\" is unavailable due to a discord"
1636
                " outage."
1637
            )
1638
1639
        return super().from_dict(data)
1640
1641
1642
@dataclass(repr=False)
1643
class UnavailableGuild(APIObject):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
1644
    id: Snowflake
1645
    unavailable: bool = True
1646