Passed
Pull Request — main (#275)
by
unknown
02:00
created

Guild.list_active_threads()   A

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
coding-style introduced by
Too many lines in module (1780/1000)
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from __future__ import annotations
5
6
from dataclasses import dataclass, field
7
from enum import IntEnum
8
from typing import AsyncGenerator, overload, TYPE_CHECKING
9
10
from .channel import Channel
11
from ...exceptions import UnavailableGuildError
12
from ...utils.api_object import APIObject
13
from ...utils.conversion import construct_client_dict, remove_none
14
from ...utils.types import MISSING
15
16
if TYPE_CHECKING:
17
    from typing import Any, Dict, List, Optional, Tuple, Union
18
    from .channel import PublicThread, PrivateThread
19
20
    from .audit_log import AuditLog
21
    from .ban import Ban
22
    from .invite import Invite
23
    from .member import GuildMember
24
    from .features import GuildFeature
25
    from .overwrite import Overwrite
26
    from .role import Role
27
    from .stage import StageInstance
28
    from .template import GuildTemplate
29
    from .welcome_screen import WelcomeScreen, WelcomeScreenChannel
30
    from .widget import GuildWidget
31
    from ..user.user import User
32
    from ..user.integration import Integration
33
    from ..voice.region import VoiceRegion
34
    from ..events.presence import PresenceUpdateEvent
35
    from ..message.emoji import Emoji
36
    from ..message.sticker import Sticker
37
    from ..user.voice_state import VoiceState
38
    from ...client import Client
39
    from ...utils.timestamp import Timestamp
40
    from ...utils.types import APINullable, JSONSerializable
41
    from ...utils.snowflake import Snowflake
42
43
44
class PremiumTier(IntEnum):
45
    """Represents the boost tier of a guild.
46
    Attributes
47
    ----------
48
    NONE:
49
        Guild has not unlocked any Server Boost perks.
50
    TIER_1:
51
        Guild has unlocked Server Boost level 1 perks.
52
    TIER_2:
53
        Guild has unlocked Server Boost level 2 perks.
54
    TIER_3:
55
        Guild has unlocked Server Boost level 3 perks.
56
    """
57
58
    NONE = 0
59
    TIER_1 = 1
60
    TIER_2 = 2
61
    TIER_3 = 3
62
63
64
class GuildNSFWLevel(IntEnum):
65
    """Represents the NSFW level of a guild.
66
    Attributes
67
    ----------
68
    DEFAULT:
69
        Default NSFW level.
70
    EXPLICIT:
71
        Explicit NSFW level.
72
    SAFE:
73
        SAFE NSFW level.
74
    AGE_RESTRICTED:
75
        Age restricted NSFW level.
76
    """
77
78
    DEFAULT = 0
79
    EXPLICIT = 1
80
    SAFE = 2
81
    AGE_RESTRICTED = 3
82
83
84
class ExplicitContentFilterLevel(IntEnum):
85
    """Represents the filter content level of a guild.
86
    Attributes
87
    ----------
88
    DISABLED:
89
        Media content will not be scanned.
90
    MEMBERS_WITHOUT_ROLES:
91
        Media content sent by members without roles will be scanned.
92
    ALL_MEMBERS:
93
        Media content sent by all members will be scanned.
94
    """
95
96
    DISABLED = 0
97
    MEMBERS_WITHOUT_ROLES = 1
98
    ALL_MEMBERS = 2
99
100
101
class MFALevel(IntEnum):
102
    """Represents the multi factor authentication level of a guild.
103
    Attributes
104
    ----------
105
    NONE:
106
        Guild has no MFA/2FA requirement for moderation actions.
107
    ELEVATED:
108
        Guild has a 2FA requirement for moderation actions
109
    """
110
111
    NONE = 0
112
    ELEVATED = 1
113
114
115
class VerificationLevel(IntEnum):
116
    """Represents the verification level of a guild.
117
    Attributes
118
    ----------
119
    NONE:
120
        Unrestricted.
121
    LOW:
122
        Must have verified email on account.
123
    MEDIUM:
124
        Must be registered on Discord for longer than 5 minutes.
125
    HIGH:
126
        Must be a member of the server for longer than 10 minutes.
127
    VERY_HIGH:
128
        Must have a verified phone number.
129
    """
130
131
    NONE = 0
132
    LOW = 1
133
    MEDIUM = 2
134
    HIGH = 3
135
    VERY_HIGH = 4
136
137
138
class DefaultMessageNotificationLevel(IntEnum):
139
    """Represents the default message notification level of a guild.
140
    Attributes
141
    ----------
142
    ALL_MESSAGES:
143
        Members will receive notifications for all messages by default.
144
    ONLY_MENTIONS:
145
        Members will receive notifications only for messages that @mention them by default.
146
    """
147
148
    # noqa: E501
149
    ALL_MESSAGES = 0
150
    ONLY_MENTIONS = 1
151
152
153
class SystemChannelFlags(IntEnum):
154
    """Represents the system channel flags of a guild.
155
    Attributes
156
    ----------
157
    SUPPRESS_JOIN_NOTIFICATIONS:
158
        Suppress member join notifications.
159
    SUPPRESS_PREMIUM_SUBSCRIPTIONS:
160
        Suppress server boost notifications.
161
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS:
162
        Suppress server setup tips.
163
    SUPPRESS_JOIN_NOTIFICATION_REPLIES:
164
        Hide member join sticker reply buttons
165
    """
166
167
    SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0
168
    SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
169
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS = 1 << 2
170
    SUPPRESS_JOIN_NOTIFICATION_REPLIES = 1 << 3
171
172
173
@dataclass
174
class GuildPreview(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (10/7)
Loading history...
175
    """Represents a guild preview.
176
    Attributes
177
    ----------
178
    id: :class:`Snowflake`
179
        The guild ID.
180
    name: :class:`str`
181
        The guild name.
182
    icon: :class:`str`
183
        The guild icon hash.
184
    splash: :class:`str`
185
        The guild splash hash.
186
    discovery_splash: :class:`str`
187
        The guild discovery splash hash.
188
    emojis: :class:`List[Emoji]`
189
        The guild emojis.
190
    features: :class:`List[GuildFeature]`
191
        The guild features.
192
    approximate_member_count: :class:`int`
193
        The approximate member count.
194
    approximate_presence_count: :class:`int`
195
        The approximate number of online members in this guild
196
    description: :class:`str`
197
        The guild description.
198
    """
199
200
    id: Snowflake
201
    name: str
202
    emojis: List[Emoji]
203
    features: List[GuildFeature]
204
    approximate_member_count: int
205
    approximate_presence_count: int
206
207
    icon: APINullable[str] = MISSING
208
    splash: APINullable[str] = MISSING
209
    discovery_splash: APINullable[str] = MISSING
210
    description: APINullable[str] = MISSING
211
212
213
@dataclass
214
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 (53/20)
Loading history...
215
    """Represents a Discord guild/server in which your client resides.
216
    Attributes
217
    ----------
218
    afk_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
219
        Id of afk channel
220
    afk_timeout: :class:`int`
221
        Afk timeout in seconds
222
    application_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
223
        Application id of the guild creator if it is bot-created
224
    banner: Optional[:class:`str`]
225
        Banner hash
226
    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...
227
        Default message notifications level
228
    description: Optional[:class:`str`]
229
        The description of a Community guild
230
    discovery_splash: Optional[:class:`str`]
231
        Discovery splash hash;
232
        only present for guilds with the "DISCOVERABLE" feature
233
    emojis: List[:class:`~pincer.objects.message.emoji.Emoji`]
234
        Custom guild emojis
235
    explicit_content_filter: :class:`~pincer.objects.guild.guild.ExplicitContentFilterLevel`
236
        Explicit content filter level
237
    features: List[:class:`~pincer.objects.guild.features.GuildFeature`]
238
        Enabled guild features
239
    id: :class:`~pincer.utils.snowflake.Snowflake`
240
        Guild id
241
    icon: Optional[:class:`str`]
242
        Icon hash
243
    mfa_level: :class:`~pincer.objects.guild.guild.MFALevel`
244
        Required MFA level for the guild
245
    name: :class:`str`
246
        Guild name (2-100 characters, excluding trailing and leading
247
        whitespace)
248
    nsfw_level: :class:`~pincer.objects.guild.guild.NSFWLevel`
249
        Guild NSFW level
250
    owner_id: :class:`~pincer.utils.snowflake.Snowflake`
251
        Id of owner
252
    preferred_locale: :class:`str`
253
        The preferred locale of a Community guild;
254
        used in server discovery and notices from Discord;
255
        defaults to "en-US"
256
    premium_tier: :class:`~pincer.objects.guild.guild.PremiumTier`
257
        Premium tier (Server Boost level)
258
    public_updates_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
259
        The id of the channel where admins
260
        and moderators of Community guilds receive notices from Discord
261
    roles: List[:class:`~pincer.objects.guild.role.Role`]
262
        Roles in the guild
263
    rules_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
264
        The id of the channel where Community guilds can display rules
265
        and/or guidelines
266
    splash: Optional[:class:`str`]
267
        Splash hash
268
    system_channel_flags: :class:`~pincer.objects.guild.guild.SystemChannelFlags`
269
        System channel flags
270
    system_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
271
        The id of the channel where guild notices
272
        such as welcome messages and boost events are posted
273
    vanity_url_code: Optional[:class:`str`]
274
        The vanity url code for the guild
275
    verification_level: :class:`~pincer.objects.guild.guild.VerificationLevel`
276
        Verification level required for the guild
277
    approximate_member_count: APINullable[:class:`int`]
278
        Approximate number of members in this guild, returned from the
279
        `GET /guilds/<id>` endpoint when with_counts is true
280
    approximate_presence_count: APINullable[:class:`int`]
281
        Approximate number of non-offline members in this guild,
282
        returned from the `GET /guilds/<id>`
283
        endpoint when with_counts is true
284
    channels: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
285
        Channels in the guild
286
    icon_hash: APINullable[Optional[:class:`str`]]
287
        Icon hash, returned when in the template object
288
    joined_at: APINullable[:class:`~pincer.utils.timestamp.Timestamp`]
289
        When this guild was joined at
290
    large: APINullable[:class:`bool`]
291
        True if this is considered a large guild
292
    max_members: APINullable[:class:`int`]
293
        The maximum number of members for the guild
294
    max_presences: APINullable[Optional[:class:`int`]]
295
        The maximum number of presences for the guild
296
        (null is always returned, apart from the largest of guilds)
297
    max_video_channel_users: APINullable[:class:`int`]
298
        The maximum amount of users in a video channel
299
    members: APINullable[List[:class:`~pincer.objects.guild.member.GuildMember`]]
300
        Users in the guild
301
    member_count: APINullable[:class:`bool`]
302
        Total number of members in this guild
303
    nsfw: APINullable[:class:`bool`]
304
        Boolean if the server is NSFW
305
    owner: APINullable[:class:`bool`]
306
        True if the user is the owner of the guild
307
    permissions: APINullable[:class:`str`]
308
        Total permissions for the user in the guild
309
        (excludes overwrites)
310
    premium_subscription_count: APINullable[:class:`int`]
311
        The number of boosts this guild currently has
312
    presences: APINullable[List[:class:`~pincer.objects.events.presence.PresenceUpdateEvent`]]
313
        Presences of the members in the guild,
314
        will only include non-offline members if the size is greater
315
        than large threshold
316
    stage_instances: APINullable[List[:class:`~pincer.objects.guild.stage.StageInstance`]]
317
        Stage instances in the guild
318
    stickers: Optional[List[:class:`~pincer.objects.message.sticker.Sticker`]]
319
        Custom guild stickers
320
    region: APINullable[Optional[:class:`str`]]
321
        Voice region id for the guild (deprecated)
322
    threads: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
323
        All active threads in the guild that current user
324
        has permission to view
325
    unavailable: APINullable[:class:`bool`]
326
        True if this guild is unavailable due to an outage
327
    voice_states: APINullable[List[:class:`~pincer.objects.user.voice_state.VoiceState`]]
328
        States of members currently in voice channels;
329
        lacks the guild_id key
330
    widget_enabled: APINullable[:class:`bool`]
331
        True if the server widget is enabled
332
    widget_channel_id: APINullable[Optional[:class:`~pincer.utils.snowflake.Snowflake`]]
333
        The channel id that the widget will generate an invite to,
334
        or null if set to no invite
335
    welcome_screen: APINullable[:class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`]
336
        The welcome screen of a Community guild, shown to new members,
337
        returned in an Invite's guild object
338
    """
339
340
    # noqa: E501
341
    afk_timeout: int
342
    default_message_notifications: DefaultMessageNotificationLevel
343
    emojis: List[Emoji]
344
    explicit_content_filter: ExplicitContentFilterLevel
345
    features: List[GuildFeature]
346
    id: Snowflake
347
    mfa_level: MFALevel
348
    name: str
349
    nsfw_level: GuildNSFWLevel
350
    owner_id: Snowflake
351
    preferred_locale: str
352
    premium_tier: PremiumTier
353
    roles: List[Role]
354
    system_channel_flags: SystemChannelFlags
355
    verification_level: VerificationLevel
356
357
    guild_scheduled_events: APINullable[List] = MISSING
358
    lazy: APINullable[bool] = MISSING
359
    premium_progress_bar_enabled: APINullable[bool] = MISSING
360
    guild_hashes: APINullable[Dict] = MISSING
361
    afk_channel_id: APINullable[Snowflake] = MISSING
362
    application_id: APINullable[Snowflake] = MISSING
363
    embedded_activities: APINullable[List] = MISSING
364
    banner: APINullable[str] = MISSING
365
    description: APINullable[str] = MISSING
366
    discovery_splash: APINullable[str] = MISSING
367
    icon: APINullable[str] = MISSING
368
    public_updates_channel_id: APINullable[Snowflake] = MISSING
369
    rules_channel_id: APINullable[Snowflake] = MISSING
370
    splash: APINullable[str] = MISSING
371
    system_channel_id: APINullable[Snowflake] = MISSING
372
    vanity_url_code: APINullable[str] = MISSING
373
374
    application_command_counts: APINullable[Dict] = MISSING
375
    application_command_count: APINullable[int] = MISSING
376
    approximate_member_count: APINullable[int] = MISSING
377
    approximate_presence_count: APINullable[int] = MISSING
378
    channels: APINullable[List[Channel]] = field(default_factory=list)
379
    # 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...
380
    hub_type: APINullable[Any] = MISSING
381
    icon_hash: APINullable[Optional[str]] = MISSING
382
    joined_at: APINullable[Timestamp] = MISSING
383
    large: APINullable[bool] = MISSING
384
    max_members: APINullable[int] = MISSING
385
    max_presences: APINullable[Optional[int]] = MISSING
386
    max_video_channel_users: APINullable[int] = MISSING
387
    members: APINullable[List[GuildMember]] = MISSING
388
    member_count: APINullable[bool] = MISSING
389
    nsfw: APINullable[bool] = MISSING
390
    # Note: This is missing from discord's docs but in the api
391
    owner: APINullable[bool] = MISSING
392
    permissions: APINullable[str] = MISSING
393
    premium_subscription_count: APINullable[int] = MISSING
394
    presences: APINullable[List[PresenceUpdateEvent]] = MISSING
395
    stage_instances: APINullable[List[StageInstance]] = MISSING
396
    stickers: APINullable[List[Sticker]] = MISSING
397
    region: APINullable[Optional[str]] = MISSING
398
    threads: APINullable[List[Channel]] = MISSING
399
    # Guilds are considered available unless otherwise specified
400
    unavailable: APINullable[bool] = False
401
    voice_states: APINullable[List[VoiceState]] = MISSING
402
    widget_enabled: APINullable[bool] = MISSING
403
    widget_channel_id: APINullable[Optional[Snowflake]] = MISSING
404
    welcome_screen: APINullable[WelcomeScreen] = MISSING
405
406
    @classmethod
407
    async def from_id(cls, client: Client, _id: Union[int, Snowflake]) -> Guild:
408
        """
409
        Parameters
410
        ----------
411
        client : :class:`~pincer.Client`
412
            Client object to use the http gateway from.
413
        _id : :class:`pincer.utils.snowflake.Snowflake`
414
            Guild ID.
415
        Returns
416
        -------
417
        :class:`~pincer.objects.guild.guild.Guild`
418
            The new guild object.
419
        """
420
        data = await client.http.get(f"/guilds/{_id}")
421
        channel_data = await client.http.get(f"/guilds/{_id}/channels")
422
423
        data["channels"]: List[Channel] = [
424
            Channel.from_dict({**i, "_client": client, "_http": client.http})
425
            for i in (channel_data or [])
426
        ]
427
428
        return Guild.from_dict(construct_client_dict(client, data))
429
430
    async def get_member(self, _id: int) -> GuildMember:
431
        """|coro|
432
        Fetches a GuildMember from its identifier
433
434
        Parameters
435
        ----------
436
        _id: int
437
            The id of the guild member which should be fetched from the Discord
438
            gateway.
439
        Returns
440
        -------
441
        :class:`~pincer.objects.guild.member.GuildMember`
442
            A GuildMember object.
443
        """
444
        return await GuildMember.from_id(self._client, self.id, _id)
445
446
    @overload
447
    async def modify_member(
448
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
449
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
450
        _id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
451
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
452
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
453
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
454
        deaf: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
455
        channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
456
    ) -> GuildMember:
457
        """|coro|
458
        Modifies a member in the guild from its identifier and based on the
459
        keyword arguments provided.
460
        Parameters
461
        ----------
462
        _id : int
463
            Id of the member to modify
464
        nick : Optional[:class:`str`]
465
            New nickname for the member |default| :data:`None`
466
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake]]
467
            New roles for the member |default| :data:`None`
468
        mute : Optional[:class:`bool`]
469
            Whether the member is muted |default| :data:`None`
470
        deaf : Optional[:class:`bool`]
471
            Whether the member is deafened |default| :data:`None`
472
        channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake]
473
            Voice channel id to move to |default| :data:`None`
474
        Returns
475
        -------
476
        :class:`~pincer.objects.guild.member.GuildMember`
477
            The new member object.
478
        """
479
        ...
480
481
    async def modify_member(self, _id: int, **kwargs) -> GuildMember:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
482
        data = await self._http.patch(
483
            f"guilds/{self.id}/members/{_id}", data=kwargs
484
        )
485
        return GuildMember.from_dict(construct_client_dict(self._client, data))
486
487
      
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
488
    @overload
489
    async def create_channel(
0 ignored issues
show
best-practice introduced by
Too many arguments (11/5)
Loading history...
490
        self, 
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
491
        name: str,               
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
492
        type: Optional[int] = None,
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 type.

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

Loading history...
493
        topic: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
494
        bitrate: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
495
        user_limit: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
496
        rate_limit_per_user: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
497
        position: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
498
        permission_overwrites: Optional[List[Overwrite]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
499
        parent_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
500
        nsfw: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
501
    ) -> Channel:
502
        """|coro|
503
        Create a new channel object for the guild.
504
505
        Parameters
506
        ----------
507
        name : str
508
            channel name (1-100 characters)
509
        type : Optional[:class:int`]
510
            the type of channel
511
        topic : Optional[:class:str`]
512
            channel topic (0-1024 characters)
513
        bitrate : Optional[:class:`int`]
514
            the bitrate (in bits) of the voice channel (voice only)
515
        user_limit : Optional[:class:`int`]
516
            the user limit of the voice channel (voice only)
517
        rate_limit_per_user : Optional[:class:`int`]
518
            amount of seconds a user has to wait before sending another message (0-21600)
519
            bots, as well as users with the permission manage_messages or manage_channel, are unaffected
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
520
        position : Optional[:class:`int`]
521
            sorting position of the channel
522
        permission_overwrites : Optional[List[:class:`~pincer.objects.guild.overwrite.Overwrite`]]
523
            the channel's permission overwrites
524
        parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
525
            id of the parent category for a channel
526
        nsfw : Optional[:class:`bool`]
527
            whether the channel is nsfw
528
529
        """
530
        ...
531
532
    async def create_channel(self, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
533
        data = await self._http.post(f"guilds/{self.id}/channels", data=kwargs)
534
        return Channel.from_dict(construct_client_dict(self._client, data))
535
536
    async def modify_channel_positions(
537
        self, *channel: Dict[str, Optional[Union[int, bool, Snowflake]]]
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
538
    ):
539
        """|coro|
540
        Create a new channel object for the guild.
541
542
        Parameters
543
        ----------
544
545
        \\*channel : Dict[str, Optional[Union[int, bool, :class:`~pincer.utils.snowflake.Snowflake`]
546
            Keys:
547
                - id : :class:`~pincer.utils.snowflake.Snowflake`
548
                - position : Optional[:class:`int`]
549
                - lock_permissions : Optional[:class:`bool`]
550
                - parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
551
552
        """
553
554
    async def list_active_threads(self) -> Tuple[
555
        List[Union[PublicThread, PrivateThread]], List[GuildMember]]:
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
556
        """|coro|
557
        Returns all active threads in the guild, including public and private threads.
558
        """
559
        data = await self._http.get(f"guilds/{self.id}/threads/active")
560
561
        threads = [Channel.from_dict(channel) for channel in data["threads"]]
562
        members = [GuildMember.from_dict(member) for member in data["members"]]
563
564
        return threads, members
565
566
    async def list_guild_members(self, limit: int = 1, after: int = 0):
567
        """|coro|
568
        Returns a list of guild member objects that are members of the guild.
569
570
        Parameters
571
        ----------
572
        limit : int
573
            max number of members to return (1-1000) |default| :data:`1`
574
        after : int
575
            the highest user id in the previous page |default| :data:`0`
576
        """
577
578
        return await self._http.get(
579
            f"guilds/{self.id}/members?limit={limit}&after={after}"
580
        )
581
582
    async def search_guild_members(
583
        self, query: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
584
        limit: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
585
    ) -> List[GuildMember]:
586
        """|coro|
587
        Returns a list of guild member objects whose username or nickname starts with a provided string.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
588
589
        Parameters
590
        ----------
591
        query : str
592
            Query string to match username(s) and nickname(s) against.
593
        limit : Optional[int]
594
            max number of members to return (1-1000) |default| :data:`1`
595
596
        """
597
598
        data = await self._http.get(
599
            f"guilds/{id}/members/search?query={query}"
600
            f"&{limit}" if limit else ""
601
        )
602
603
        return [GuildMember.from_dict(member) for member in data]
604
605
    @overload
606
    async def add_guild_member(
607
        self, *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
608
        user_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
609
        access_token: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
610
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
611
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
612
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
613
        deaf: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
614
    ) -> Optional[GuildMember]:
615
        """|coro|
616
        Adds a user to the guild, provided you have a valid oauth2 access token for the user with the guilds.join scope.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (120/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
617
618
        Parameters
619
        ----------
620
        user_id : str
621
            id of the user to be added
622
        access_token : str
623
            an oauth2 access token granted with the guilds.join to the bot's application for the user you want to add to the guild
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (130/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
624
        nick : Optional[str]
625
        	value to set users nickname to
626
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
627
        	array of role ids the member is assigned
628
        mute : Optional[bool]
629
        	whether the user is muted in voice channels
630
        deaf : Optional[bool]
631
        	whether the user is deafened in voice channels
632
633
        Returns
634
        -------
635
        :class:`~pincer.objects.guild.member.GuildMember`
636
            If the user is not in the guild
637
        None
638
            If the user is in the guild
639
        """
640
641
    async def add_guild_member(self, user_id, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
642
        data = self._http.put(f"guilds/{self.id}/members/{user_id}",
643
                              data=kwargs)
644
645
        return GuildMember.from_dict(data) if data else None
646
647
    async def modify_current_member(self, nick: str) -> GuildMember:
648
        """|coro|
649
        Modifies the current member in a guild.
650
651
        Parameters
652
        ----------
653
        nick : str
654
            value to set users nickname to
655
        """
656
        data = self._http.patch(f"guilds/{self.id}/members/@me", {"nick": nick})
657
        member = GuildMember.from_dict(data)
658
        return member
659
660
    async def add_guild_member_role(self, user_id: int, role_id: int) -> None:
661
        """|coro|
662
        Adds a role to a guild member.
663
664
        Parameters
665
        ----------
666
        user_id : int
667
            id of the user to give a role to
668
        role_id : int
669
            id of a role
670
        """
671
        data = await self._http.put(
0 ignored issues
show
Unused Code introduced by
The variable data seems to be unused.
Loading history...
672
            f"guilds/{self.id}/{user_id}/roles/{role_id}", {})
673
        # TODO: remove the blank dictionary once #233 is fixed
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
674
675
    async def remove_guild_member_role(self, user_id: int,
676
                                       role_id: int) -> None:
677
        """|coro|
678
        Removes a role from a guild member.
679
680
        Parameters
681
        ----------
682
        user_id : int
683
            id of the user to remove a role from
684
        role_id : int
685
            id of a role
686
        """
687
        await self._http.delete(
688
            f"guilds/{self.id}/{user_id}/roles/{role_id}",
689
        )
690
        # TODO: remove the blank dictionary and format once #233 is fixed
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
691
692
    async def remove_guild_member(self, user_id: int) -> None:
693
        """|coro|
694
        Remove a member from a guild.
695
696
        Parameters
697
        ----------
698
        user_id : int
699
            id of the user to remove from the guild
700
        """
701
        await self._http.delete(f"guilds/{self.id}/members/{user_id}")
702
703
    async def ban(
704
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
705
        member_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
706
        reason: str = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
707
        delete_message_days: int = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
708
    ):
709
        """
710
        Parameters
711
        ----------
712
        member_id : :class:`int`
713
            ID of the guild member to ban.
714
        reason : Optional[:class:`str`]
715
            Reason for the kick.
716
        delete_message_days : Optional[:class:`int`]
717
            Number of days to delete messages for (0-7)
718
        """
719
        headers = {}
720
721
        if reason is not None:
722
            headers["X-Audit-Log-Reason"] = reason
723
724
        data = {}
725
726
        if delete_message_days is not None:
727
            data["delete_message_days"] = delete_message_days
728
729
        await self._http.put(
730
            f"/guilds/{self.id}/bans/{member_id}",
731
            data=data,
732
            headers=headers
733
        )
734
735
    async def kick(self, member_id: int, reason: Optional[str] = None):
736
        """|coro|
737
        Kicks a guild member.
738
        Parameters
739
        ----------
740
        member_id : :class:`int`
741
            ID of the guild member to kick.
742
        reason : Optional[:class:`str`]
743
            Reason for the kick.
744
        """
745
746
        headers = {}
747
748
        if reason is not None:
749
            headers["X-Audit-Log-Reason"] = reason
750
751
        await self._http.delete(
752
            f"/guilds/{self.id}/members/{member_id}",
753
            header=headers
754
        )
755
756
    async def get_roles(self) -> AsyncGenerator[Role, None]:
757
        """|coro|
758
        Fetches all the roles in the guild.
759
760
        Yields
761
        -------
762
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
763
            An async generator of Role objects.
764
        """
765
        data = await self._http.get(f"guilds/{self.id}/roles")
766
        for role_data in data:
767
            yield Role.from_dict(construct_client_dict(self._client, role_data))
768
769
    @overload
770
    async def create_role(
771
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
772
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
773
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
774
        name: Optional[str] = "new role",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
775
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
776
        color: Optional[int] = 0,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
777
        hoist: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
778
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
779
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
780
        mentionable: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
781
    ) -> Role:
782
        """|coro|
783
        Creates a new role for the guild.
784
        Requires the ``MANAGE_ROLES`` permission.
785
786
        Parameters
787
        ----------
788
        reason : Optional[:class:`str`]
789
            Reason for creating the role. |default| :data:`None`
790
        name : Optional[:class:`str`]
791
            name of the role |default| :data:`"new role"`
792
        permissions : Optional[:class:`str`]
793
            bitwise value of the enabled/disabled
794
            permissions, set to @everyone permissions
795
            by default |default| :data:`None`
796
        color : Optional[:class:`int`]
797
            RGB color value |default| :data:`0`
798
        hoist : Optional[:class:`bool`]
799
            whether the role should be displayed
800
            separately in the sidebar |default| :data:`False`
801
        icon : Optional[:class:`str`]
802
            the role's icon image (if the guild has
803
            the ``ROLE_ICONS`` feature) |default| :data:`None`
804
        unicode_emoji : Optional[:class:`str`]
805
            the role's unicode emoji as a standard emoji (if the guild
806
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
807
        mentionable : Optional[:class:`bool`]
808
            whether the role should be mentionable |default| :data:`False`
809
810
        Returns
811
        -------
812
        :class:`~pincer.objects.guild.role.Role`
813
            The new role object.
814
        """
815
        ...
816
817
    async def create_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
818
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
819
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
820
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
821
    ) -> Role:
822
        return Role.from_dict(
823
            construct_client_dict(
824
                self._client,
825
                await self._http.post(
826
                    f"guilds/{self.id}/roles",
827
                    data=kwargs,
828
                    headers=remove_none({"X-Audit-Log-Reason": reason})
829
                ),
830
            )
831
        )
832
833
    async def edit_role_position(
834
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
835
        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...
836
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
837
        position: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
838
    ) -> AsyncGenerator[Role, None]:
839
        """|coro|
840
        Edits the position of a role.
841
842
        Parameters
843
        ----------
844
        id : :class:`~pincer.utils.snowflake.Snowflake`
845
            The role ID
846
        reason : Optional[:class:`str`]
847
            Reason for editing the role position. |default| :data:`None`
848
        position : Optional[:class:`int`]
849
            Sorting position of the role |default| :data:`None`
850
851
        Yields
852
        -------
853
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
854
            An async generator of all of the guild's role objects.
855
        """
856
        data = await self._http.patch(
857
            f"guilds/{self.id}/roles",
858
            data={"id": id, "position": position},
859
            headers=remove_none({"X-Audit-Log-Reason": reason})
860
        )
861
        for role_data in data:
862
            yield Role.from_dict(construct_client_dict(self._client, role_data))
863
864
    @overload
865
    async def edit_role(
866
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
867
        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...
868
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
869
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
870
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
871
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
872
        color: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
873
        hoist: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
874
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
875
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
876
        mentionable: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
877
    ) -> Role:
878
        """|coro|
879
        Edits a role.
880
        Requires the ``MANAGE_ROLES`` permission.
881
882
        Parameters
883
        ----------
884
        id : :class:`~pincer.utils.snowflake.Snowflake`
885
            The role ID
886
        reason : Optional[:class:`str`]
887
            Reason for editing the role |default| :data:`None`
888
        name : Optional[:class:`str`]
889
            Name of the role |default| :data:`None`
890
        permissions : Optional[:class:`str`]
891
            Bitwise value of the enabled/disabled
892
            permissions |default| :data:`None`
893
        color : Optional[:class:`int`]
894
            RGB color value |default| :data:`None`
895
        hoist : Optional[:class:`bool`]
896
            Whether the role should be displayed
897
            separately in the sidebar |default| :data:`None`
898
        icon : Optional[:class:`str`]
899
            The role's icon image (if the guild has
900
            the ``ROLE_ICONS`` feature) |default| :data:`None`
901
        unicode_emoji : Optional[:class:`str`]
902
            The role's unicode emoji as a standard emoji (if the guild
903
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
904
        mentionable : Optional[:class:`bool`]
905
            Whether the role should be mentionable |default| :data:`None`
906
907
        Returns
908
        -------
909
        :class:`~pincer.objects.guild.role.Role`
910
            The edited role object.
911
        """
912
        ...
913
914
    async def edit_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
915
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
916
        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...
917
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
918
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
919
    ) -> Role:
920
        return Role.from_dict(
921
            construct_client_dict(
922
                self._client,
923
                await self._http.patch(
924
                    f"guilds/{self.id}/roles/{id}",
925
                    data=kwargs,
926
                    headers=remove_none({"X-Audit-Log-Reason": reason})
927
                ),
928
            )
929
        )
930
931
    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...
932
        """|coro|
933
        Deletes a role.
934
        Requires the `MANAGE_ROLES` permission.
935
936
        Parameters
937
        ----------
938
        id : :class:`~pincer.utils.snowflake.Snowflake`
939
            The role ID
940
        reason : Optional[:class:`str`]
941
            The reason for deleting the role |default| :data:`None`
942
        """
943
        await self._http.delete(
944
            f"guilds/{self.id}/roles/{id}",
945
            headers=remove_none({"X-Audit-Log-Reason": reason})
946
        )
947
948
    async def get_bans(self) -> AsyncGenerator[Ban, None]:
949
        """|coro|
950
        Fetches all the bans in the guild.
951
952
        Yields
953
        -------
954
        AsyncGenerator[:class:`~pincer.objects.guild.ban.Ban`, :data:`None`]
955
            An async generator of Ban objects.
956
        """
957
        data = await self._http.get(f"guilds/{self.id}/bans")
958
        for ban_data in data:
959
            yield Ban.from_dict(construct_client_dict(self._client, ban_data))
960
961
    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...
962
        """|coro|
963
        Fetches a ban from the guild.
964
965
        Parameters
966
        ----------
967
        id : :class:`~pincer.utils.snowflake.Snowflake`
968
            The user ID
969
970
        Returns
971
        -------
972
        :class:`~pincer.objects.guild.ban.Ban`
973
            The Ban object.
974
        """
975
        return Ban.from_dict(
976
            construct_client_dict(
977
                self._client,
978
                await self._http.get(f"guilds/{self.id}/bans/{id}"),
979
            )
980
        )
981
982
    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...
983
        """|coro|
984
        Unbans a user from the guild.
985
986
        Parameters
987
        ----------
988
        id : :class:`~pincer.utils.snowflake.Snowflake`
989
            The user ID
990
        reason : Optional[:class:`str`]
991
            The reason for unbanning the user |default| :data:`None`
992
        """
993
        await self._http.delete(
994
            f"guilds/{self.id}/bans/{id}",
995
            headers=remove_none({"X-Audit-Log-Reason": reason})
996
        )
997
998
    @overload
999
    async def edit(
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (20/15).
Loading history...
1000
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1001
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1002
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1003
        region: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1004
        verification_level: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1005
        default_message_notifications: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1006
        explicit_content_filter: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1007
        afk_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1008
        afk_timeout: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1009
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1010
        owner_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1011
        splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1012
        discovery_splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1013
        banner: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1014
        system_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1015
        system_channel_flags: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1016
        rules_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1017
        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...
1018
        preferred_locale: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1019
        features: Optional[List[GuildFeature]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1020
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1021
    ) -> Guild:
1022
        """|coro|
1023
        Modifies the guild
1024
1025
        Parameters
1026
        ----------
1027
        name : Optional[:class:`str`]
1028
            Guild name |default| :data:`None`
1029
        region : Optional[:class:`str`]
1030
            Guild voice region ID |default| :data:`None`
1031
        verification_level : Optional[:class:`int`]
1032
            Verification level |default| :data:`None`
1033
        default_message_notifications : Optional[:class:`int`]
1034
            Default message notification level |default| :data:`None`
1035
        explicit_content_filter : Optional[:class:`int`]
1036
            Explicit content filter level |default| :data:`None`
1037
        afk_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1038
            ID for AFK channel |default| :data:`None`
1039
        afk_timeout : Optional[:class:`int`]
1040
            AFK timeout in seconds |default| :data:`None`
1041
        icon : Optional[:class:`str`]
1042
            base64 1024x1024 png/jpeg/gif image for the guild icon
1043
            (can be animated gif when the server
1044
            has the `ANIMATED_ICON` feature) |default| :data:`None`
1045
        owner_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1046
            User ID to transfer guild ownership to (must be owner) |default| :data:`None`
1047
        splash : Optional[:class:`str`]
1048
            base64 16:9 png/jpeg image for the guild splash (when the
1049
            server has the `INVITE_SPLASH` feature) |default| :data:`None`
1050
        discovery_splash : Optional[:class:`str`]
1051
            base64 16:9 png/jpeg image for the guild discovery splash
1052
            (when the server has the `DISCOVERABLE` feature) |default| :data:`None`
1053
        banner : Optional[:class:`str`]
1054
            base64 16:9 png/jpeg image for the guild banner (when the
1055
            server has the `BANNER` feature) |default| :data:`None`
1056
        system_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1057
            The ID of the channel where guild notices such as welcome
1058
            messages and boost events are posted |default| :data:`None`
1059
        system_channel_flags : Optional[:class:`int`]
1060
            System channel flags |default| :data:`None`
1061
        rules_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1062
            The ID of the channel where Community guilds display rules
1063
            and/or guidelines |default| :data:`None`
1064
        public_updates_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1065
            The ID of the channel where admins and moderators of
1066
            Community guilds receive notices from Discord |default| :data:`None`
1067
        preferred_locale : Optional[:class:`str`]
1068
            The preferred locale of a Community guild used in server
1069
            discovery and notices from Discord; defaults to "en-US" |default| :data:`None`
1070
        features : Optional[List[:class:`GuildFeature`]]
1071
            Enabled guild features |default| :data:`None`
1072
        description : Optional[:class:`str`]
1073
            The description for the guild, if the guild is discoverable |default| :data:`None`
1074
1075
        Returns
1076
        -------
1077
        :class:`~pincer.objects.guild.Guild`
1078
            The modified guild object.
1079
        """
1080
        ...
1081
1082
    async def edit(self, **kwargs) -> Guild:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
1083
        g = await self._http.patch(f"guilds/{self.id}", data=kwargs)
1084
        return Guild.from_dict(construct_client_dict(self._client, g))
1085
1086
    async def preview(self) -> GuildPreview:
1087
        """|coro|
1088
        Previews the guild.
1089
1090
        Returns
1091
        -------
1092
        :class:`~pincer.objects.guild.guild.GuildPreview`
1093
            The guild preview object.
1094
        """
1095
        data = await self._http.get(f"guilds/{self.id}/preview")
1096
        return GuildPreview.from_dict(data)
1097
1098
    async def delete(self):
1099
        """|coro|
1100
        Deletes the guild. Returns `204 No Content` on success.
1101
        """
1102
        await self._http.delete(f"guilds/{self.id}")
1103
1104
    async def prune_count(
1105
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1106
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1107
        include_roles: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1108
    ) -> int:
1109
        """|coro|
1110
        Returns the number of members that
1111
        would be removed in a prune operation.
1112
        Requires the ``KICK_MEMBERS`` permission.
1113
1114
        Parameters
1115
        ----------
1116
        days : Optional[:class:`int`]
1117
            Number of days to count prune for (1-30) |default| :data:`7`
1118
        include_roles : Optional[:class:`str`]
1119
            Comma-delimited array of Snowflakes;
1120
            role(s) to include |default| :data:`None`
1121
1122
        Returns
1123
        -------
1124
        :class:`int`
1125
            The number of members that would be removed.
1126
        """
1127
        return await self._http.get(
1128
            f"guilds/{self.id}/prune?{days=}&{include_roles=!s}"
1129
        )["pruned"]
1130
1131
    async def prune(
1132
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1133
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1134
        compute_prune_days: Optional[bool] = True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1135
        include_roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1136
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1137
    ) -> int:
1138
        """|coro|
1139
        Prunes members from the guild. Requires the ``KICK_MEMBERS`` permission.
1140
1141
        Parameters
1142
1143
        Parameters
1144
        ----------
1145
        days : Optional[:class:`int`]
1146
            Number of days to prune (1-30) |default| :data:`7`
1147
        compute_prune_days : Optional[:class:`bool`]
1148
            Whether ``pruned`` is returned, discouraged for large guilds
1149
            |default| :data:`True`
1150
        include_roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1151
            role(s) to include |default| :data:`None`
1152
        reason : Optional[:class:`str`]
1153
            Reason for the prune |default| :data:`None`
1154
1155
        Returns
1156
        -------
1157
        :class:`int`
1158
            The number of members that were removed.
1159
        """
1160
        return await self._http.post(
1161
            f"guilds/{self.id}/prune",
1162
            data={
1163
                "days": days,
1164
                "compute_prune_days": compute_prune_days,
1165
                "include_roles": include_roles
1166
            },
1167
            headers=remove_none({"X-Audit-Log-Reason": reason})
1168
        )["pruned"]
1169
1170
    async def get_voice_regions(self) -> AsyncGenerator[VoiceRegion, None]:
1171
        """|coro|
1172
        Returns an async generator of voice regions.
1173
1174
        Yields
1175
        -------
1176
        AsyncGenerator[:class:`~pincer.objects.voice.VoiceRegion`, :data:`None`]
1177
            An async generator of voice regions.
1178
        """
1179
        data = await self._http.get(f"guilds/{self.id}/regions")
1180
        for voice_region_data in data:
1181
            yield VoiceRegion.from_dict(construct_client_dict(self._client, voice_region_data))
1182
1183
    async def get_invites(self) -> AsyncGenerator[Invite, None]:
1184
        """|coro|
1185
        Returns an async generator of invites for the guild.
1186
        Requires the ``MANAGE_GUILD`` permission.
1187
1188
        Yields
1189
        -------
1190
        AsyncGenerator[:class:`~pincer.objects.invite.Invite`, :data:`None`]
1191
            An async generator of invites.
1192
        """
1193
        data = await self._http.get(f"guilds/{self.id}/invites")
1194
        for invite_data in data:
1195
            yield Invite.from_dict(construct_client_dict(self._client, invite_data))
1196
1197
    async def get_integrations(self) -> AsyncGenerator[Integration, None]:
1198
        """|coro|
1199
        Returns an async generator of integrations for the guild.
1200
        Requires the ``MANAGE_GUILD`` permission.
1201
1202
        Yields
1203
        -------
1204
        AsyncGenerator[:class:`~pincer.objects.integration.Integration`, :data:`None`]
1205
            An async generator of integrations.
1206
        """
1207
        data = await self._http.get(f"guilds/{self.id}/integrations")
1208
        for integration_data in data:
1209
            yield Integration.from_dict(construct_client_dict(self._client, integration_data))
1210
1211
    async def delete_integration(
1212
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1213
        integration: Integration,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1214
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1215
    ):
1216
        """|coro|
1217
        Deletes an integration.
1218
        Requires the ``MANAGE_GUILD`` permission.
1219
1220
        Parameters
1221
        ----------
1222
        integration : :class:`~pincer.objects.integration.Integration`
1223
            The integration to delete.
1224
        reason : Optional[:class:`str`]
1225
            Reason for the deletion |default| :data:`None`
1226
        """
1227
        await self._http.delete(
1228
            f"guilds/{self.id}/integrations/{integration.id}",
1229
            headers=remove_none({"X-Audit-Log-Reason": reason})
1230
        )
1231
1232
    async def get_widget_settings(self) -> GuildWidget:
1233
        """|coro|
1234
        Returns the guild widget settings.
1235
        Requires the ``MANAGE_GUILD`` permission.
1236
1237
        Returns
1238
        -------
1239
        :class:`~pincer.objects.guild.widget.GuildWidget`
1240
            The guild widget settings.
1241
        """
1242
        return GuildWidget.from_dict(
1243
            construct_client_dict(
1244
                self._client,
1245
                await self._http.get(f"guilds/{self.id}/widget")
1246
            )
1247
        )
1248
1249
    async def modify_widget(
1250
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1251
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1252
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1253
    ) -> GuildWidget:
1254
        """|coro|
1255
        Modifies the guild widget for the guild.
1256
        Requires the ``MANAGE_GUILD`` permission.
1257
1258
        Parameters
1259
        ----------
1260
        reason : Optional[:class:`str`]
1261
            Reason for the modification |default| :data:`None`
1262
        \\*\\*kwargs
1263
            The widget settings to modify
1264
1265
        Returns
1266
        -------
1267
        :class:`~pincer.objects.guild.widget.GuildWidget`
1268
            The updated GuildWidget object
1269
        """
1270
        data = await self._http.patch(
1271
            f"guilds/{self.id}/widget",
1272
            data=kwargs,
1273
            headers=remove_none({"X-Audit-Log-Reason": reason})
1274
        )
1275
        return GuildWidget.from_dict(construct_client_dict(self._client, data))
1276
1277
    async def get_widget(self) -> Dict[str, JSONSerializable]:
1278
        """|coro|
1279
        Returns the widget for the guild
1280
        """
1281
        return await self._http.get(f"guilds/{self.id}/widget.json")
1282
1283
    @property
1284
    async def vanity_url(self) -> Invite:
1285
        """|coro|
1286
        Returns the Vanity URL for the guild.
1287
        Requires the ``MANAGE_GUILD`` permission.
1288
        ``code`` will be null if a vanity URL has not been set.
1289
1290
        Returns
1291
        -------
1292
        :class:`~pincer.objects.guild.invite.Invite`
1293
            The vanity url for the guild.
1294
        """
1295
        data = await self._http.get(f"guilds/{self.id}/vanity-url")
1296
        return Invite.from_dict(construct_client_dict(self._client, data))
1297
1298
    async def get_widget_image(self, style: Optional[str] = "shield") -> str:  # TODO Replace str with ImageURL object
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
Coding Style introduced by
This line is too long as per the coding-style (118/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
1299
        """|coro|
1300
        Returns a PNG image widget for the guild.
1301
        Requires no permissions or authentication.
1302
1303
        Widget Style Options
1304
        -------------------
1305
        * [``shield``](https://discord.com/api/guilds/81384788765712384/widget.png?style=shield)
1306
          shield style widget with Discord icon and guild members online count
1307
        * [``banner1``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner1)
1308
          large image with guild icon, name and online count.
1309
          "POWERED BY DISCORD" as the footer of the widget
1310
        * [``banner2``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner2)
1311
          smaller widget style with guild icon, name and online count.
1312
          Split on the right with Discord logo
1313
        * [``banner3``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner3)
1314
          large image with guild icon, name and online count.
1315
          In the footer, Discord logo on the
1316
          left and "Chat Now" on the right
1317
        * [``banner4``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner4)
1318
          large Discord logo at the top of the widget.
1319
          Guild icon, name and online count in the middle portion
1320
          of the widget and a "JOIN MY SERVER" button at the bottom
1321
1322
        Parameters
1323
        ----------
1324
        style : Optional[:class:`str`]
1325
            Style of the widget image returned |default| :data:`"shield"`
1326
1327
        Returns
1328
        -------
1329
        :class:`str`
1330
            A PNG image of the guild widget.
1331
        """
1332
        return await self._http.get(f"guilds/{self.id}/widget.png?{style=!s}")
1333
1334
    async def get_welcome_screen(self) -> WelcomeScreen:
1335
        """Returns the welcome screen for the guild.
1336
1337
        Returns
1338
        -------
1339
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1340
            The welcome screen for the guild.
1341
        """
1342
        data = await self._http.get(f"guilds/{self.id}/welcome-screen")
1343
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1344
1345
    async def modify_welcome_screen(
1346
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1347
        enabled: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1348
        welcome_channels: Optional[List[WelcomeScreenChannel]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1349
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1350
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1351
    ) -> WelcomeScreen:
1352
        """|coro|
1353
        Modifies the guild's Welcome Screen.
1354
        Requires the ``MANAGE_GUILD`` permission.
1355
1356
        Parameters
1357
        ----------
1358
        enabled : Optional[:class:`bool`]
1359
            Whether the welcome screen is enabled |default| :data:`None`
1360
        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...
1361
            Channels linked in the welcome screen and
1362
            their display options |default| :data:`None`
1363
        description : Optional[:class:`str`]
1364
            The server description to show
1365
            in the welcome screen |default| :data:`None`
1366
        reason : Optional[:class:`str`]
1367
            Reason for the modification |default| :data:`None`
1368
1369
        Returns
1370
        -------
1371
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1372
            The updated WelcomeScreen object
1373
        """
1374
        data = await self._http.patch(
1375
            f"guilds/{self.id}/welcome-screen",
1376
            data={
1377
                "enabled": enabled,
1378
                "welcome_channels": welcome_channels,
1379
                "description": description
1380
            },
1381
            headers=remove_none({"X-Audit-Log-Reason": reason})
1382
        )
1383
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1384
1385
    async def modify_current_user_voice_state(
1386
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1387
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1388
        suppress: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1389
        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...
1390
    ):
1391
        """|coro|
1392
        Updates the current user's voice state.
1393
1394
        There are currently several caveats for this endpoint:
1395
        * ``channel_id`` must currently point to a stage channel
1396
        * current user must already have joined ``channel_id``
1397
        * You must have the ``MUTE_MEMBERS`` permission to
1398
          unsuppress yourself. You can always suppress yourself.
1399
        * You must have the ``REQUEST_TO_SPEAK`` permission to request
1400
          to speak. You can always clear your own request to speak.
1401
        * You are able to set ``request_to_speak_timestamp`` to any
1402
          present or future time.
1403
1404
        Parameters
1405
        ----------
1406
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1407
            The ID of the channel the user is currently in
1408
        suppress : Optional[:class:`bool`]
1409
            Toggles the user's suppress state |default| :data:`None`
1410
        request_to_speak_timestamp : Optional[:class:`~pincer.utils.timestamp.Timestamp`]
1411
            Sets the user's request to speak
1412
        """
1413
        await self._http.patch(
1414
            f"guilds/{self.id}/voice-states/@me",
1415
            data={
1416
                "channel_id": channel_id,
1417
                "suppress": suppress,
1418
                "request_to_speak_timestamp": request_to_speak_timestamp
1419
            }
1420
        )
1421
1422
    async def modify_user_voice_state(
1423
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1424
        user: User,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1425
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1426
        suppress: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1427
    ):
1428
        """|coro|
1429
        Updates another user's voice state.
1430
1431
        There are currently several caveats for this endpoint:
1432
        * ``channel_id`` must currently point to a stage channel
1433
        * User must already have joined ``channel_id``
1434
        * You must have the ``MUTE_MEMBERS`` permission.
1435
          (Since suppression is the only thing that is available currently.)
1436
        * When unsuppressed, non-bot users will have their
1437
          ``request_to_speak_timestamp`` set to the current time.
1438
          Bot users will not.
1439
        * When suppressed, the user will have their
1440
          ``request_to_speak_timestamp`` removed.
1441
1442
        Parameters
1443
        ----------
1444
        user : :class:`~pincer.objects.guild.member.Member`
1445
            The user to update
1446
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1447
            The ID of the channel the user is currently in
1448
        suppress : Optional[:class:`bool`]
1449
            Toggles the user's suppress state |default| :data:`None`
1450
        """
1451
        await self._http.patch(
1452
            f"guilds/{self.id}/voice-states/{user.id}",
1453
            data={
1454
                "channel_id": channel_id,
1455
                "suppress": suppress
1456
            }
1457
        )
1458
1459
    async def get_audit_log(self) -> AuditLog:
1460
        """|coro|
1461
        Returns an audit log object for the guild.
1462
        Requires the ``VIEW_AUDIT_LOG`` permission.
1463
1464
        Returns
1465
        -------
1466
        :class:`~pincer.objects.guild.audit_log.AuditLog`
1467
            The audit log object for the guild.
1468
        """
1469
        return AuditLog.from_dict(
1470
            construct_client_dict(
1471
                self._client,
1472
                await self._http.get(f"guilds/{self.id}/audit-logs")
1473
            )
1474
        )
1475
1476
    async def get_emojis(self) -> AsyncGenerator[Emoji, None]:
1477
        """|coro|
1478
        Returns an async generator of the emojis in the guild.
1479
1480
        Yields
1481
        ------
1482
        :class:`~pincer.objects.guild.emoji.Emoji`
1483
            The emoji object.
1484
        """
1485
        data = await self._http.get(f"guilds/{self.id}/emojis")
1486
        for emoji_data in data:
1487
            yield Emoji.from_dict(
1488
                construct_client_dict(self._client, emoji_data)
1489
            )
1490
1491
    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...
1492
        """|coro|
1493
        Returns an emoji object for the given ID.
1494
1495
        Parameters
1496
        ----------
1497
        id : :class:`~pincer.utils.snowflake.Snowflake`
1498
            The ID of the emoji
1499
1500
        Returns
1501
        -------
1502
        :class:`~pincer.objects.guild.emoji.Emoji`
1503
            The emoji object.
1504
        """
1505
        return Emoji.from_dict(
1506
            construct_client_dict(
1507
                self._client,
1508
                await self._http.get(f"guilds/{self.id}/emojis/{id}")
1509
            )
1510
        )
1511
1512
    async def create_emoji(
1513
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1514
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1515
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1516
        image: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1517
        roles: List[Snowflake],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1518
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1519
    ) -> Emoji:
1520
        """|coro|
1521
        Creates a new emoji for the guild.
1522
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1523
1524
        Emojis and animated emojis have a maximum file size of 256kb.
1525
        Attempting to upload an emoji larger than this limit will fail.
1526
1527
        Parameters
1528
        ----------
1529
        name : :class:`str`
1530
            Name of the emoji
1531
        image : :class:`str`
1532
            The 128x128 emoji image data
1533
        roles : List[:class:`~pincer.utils.snowflake.Snowflake`]
1534
            Roles allowed to use this emoji
1535
        reason : Optional[:class:`str`]
1536
            The reason for creating the emoji |default| :data:`None`
1537
1538
        Returns
1539
        -------
1540
        :class:`~pincer.objects.guild.emoji.Emoji`
1541
            The newly created emoji object.
1542
        """
1543
        data = await self._http.post(
1544
            f"guilds/{self.id}/emojis",
1545
            data={
1546
                "name": name,
1547
                "image": image,
1548
                "roles": roles
1549
            },
1550
            headers=remove_none({"X-Audit-Log-Reason": reason})
1551
        )
1552
        return Emoji.from_dict(
1553
            construct_client_dict(self._client, data)
1554
        )
1555
1556
    async def edit_emoji(
1557
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1558
        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...
1559
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1560
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1561
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1562
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1563
    ) -> Emoji:
1564
        """|coro|
1565
        Modifies the given emoji.
1566
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1567
1568
        Parameters
1569
        ----------
1570
        id : :class:`~pincer.utils.snowflake.Snowflake`
1571
            The ID of the emoji
1572
        name : Optional[:class:`str`]
1573
            Name of the emoji |default| :data:`None`
1574
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1575
            Roles allowed to use this emoji |default| :data:`None`
1576
        reason : Optional[:class:`str`]
1577
            The reason for editing the emoji |default| :data:`None`
1578
1579
        Returns
1580
        -------
1581
        :class:`~pincer.objects.guild.emoji.Emoji`
1582
            The modified emoji object.
1583
        """
1584
        data = await self._http.patch(
1585
            f"guilds/{self.id}/emojis/{id}",
1586
            data={
1587
                "name": name,
1588
                "roles": roles
1589
            },
1590
            headers=remove_none({"X-Audit-Log-Reason": reason})
1591
        )
1592
        return Emoji.from_dict(
1593
            construct_client_dict(self._client, data)
1594
        )
1595
1596
    async def delete_emoji(
1597
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1598
        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...
1599
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1600
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1601
    ):
1602
        """|coro|
1603
        Deletes the given emoji.
1604
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1605
1606
        Parameters
1607
        ----------
1608
        id : :class:`~pincer.utils.snowflake.Snowflake`
1609
            The ID of the emoji
1610
        reason : Optional[:class:`str`]
1611
            The reason for deleting the emoji |default| :data:`None`
1612
        """
1613
        await self._http.delete(
1614
            f"guilds/{self.id}/emojis/{id}",
1615
            headers=remove_none({"X-Audit-Log-Reason": reason})
1616
        )
1617
1618
    async def get_templates(self) -> AsyncGenerator[GuildTemplate, None]:
1619
        """|coro|
1620
        Returns an async generator of the guild templates.
1621
1622
        Yields
1623
        -------
1624
        AsyncGenerator[:class:`~pincer.objects.guild.template.GuildTemplate`, :data:`None`]
1625
            The guild template object.
1626
        """
1627
        data = await self._http.get(f"guilds/{self.id}/templates")
1628
        for template_data in data:
1629
            yield GuildTemplate.from_dict(
1630
                construct_client_dict(self._client, template_data)
1631
            )
1632
1633
    async def create_template(
1634
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1635
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1636
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1637
    ) -> GuildTemplate:
1638
        """|coro|
1639
        Creates a new template for the guild.
1640
        Requires the ``MANAGE_GUILD`` permission.
1641
1642
        Parameters
1643
        ----------
1644
        name : :class:`str`
1645
            Name of the template (1-100 characters)
1646
        description : Optional[:class:`str`]
1647
            Description of the template
1648
            (0-120 characters) |default| :data:`None`
1649
        Returns
1650
        -------
1651
        :class:`~pincer.objects.guild.template.GuildTemplate`
1652
            The newly created template object.
1653
        """
1654
        data = await self._http.post(
1655
            f"guilds/{self.id}/templates",
1656
            data={
1657
                "name": name,
1658
                "description": description
1659
            }
1660
        )
1661
        return GuildTemplate.from_dict(
1662
            construct_client_dict(self._client, data)
1663
        )
1664
1665
    async def sync_template(
1666
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1667
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1668
    ) -> GuildTemplate:
1669
        """|coro|
1670
        Syncs the given template.
1671
        Requires the ``MANAGE_GUILD`` permission.
1672
1673
        Parameters
1674
        ----------
1675
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1676
            The template to sync
1677
1678
        Returns
1679
        -------
1680
        :class:`~pincer.objects.guild.template.GuildTemplate`
1681
            The synced template object.
1682
        """
1683
        data = await self._http.put(
1684
            f"guilds/{self.id}/templates/{template.code}"
1685
        )
1686
        return GuildTemplate.from_dict(
1687
            construct_client_dict(self._client, data)
1688
        )
1689
1690
    async def edit_template(
1691
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1692
        template: GuildTemplate,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1693
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1694
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1695
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1696
    ) -> GuildTemplate:
1697
        """|coro|
1698
        Modifies the template's metadata.
1699
        Requires the ``MANAGE_GUILD`` permission.
1700
1701
        Parameters
1702
        ----------
1703
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1704
            The template to edit
1705
        name : Optional[:class:`str`]
1706
            Name of the template (1-100 characters)
1707
            |default| :data:`None`
1708
        description : Optional[:class:`str`]
1709
            Description of the template (0-120 characters)
1710
            |default| :data:`None`
1711
1712
        Returns
1713
        -------
1714
        :class:`~pincer.objects.guild.template.GuildTemplate`
1715
            The edited template object.
1716
        """
1717
        data = await self._http.patch(
1718
            f"guilds/{self.id}/templates/{template.code}",
1719
            data={
1720
                "name": name,
1721
                "description": description
1722
            }
1723
        )
1724
        return GuildTemplate.from_dict(
1725
            construct_client_dict(self._client, data)
1726
        )
1727
1728
    async def delete_template(
1729
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1730
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1731
    ) -> GuildTemplate:
1732
        """|coro|
1733
        Deletes the given template.
1734
        Requires the ``MANAGE_GUILD`` permission.
1735
1736
        Parameters
1737
        ----------
1738
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1739
            The template to delete
1740
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1741
        Returns
1742
        -------
1743
        :class:`~pincer.objects.guild.template.GuildTemplate`
1744
            The deleted template object.
1745
        """
1746
        data = await self._http.delete(
1747
            f"guilds/{self.id}/templates/{template.code}"
1748
        )
1749
        return GuildTemplate.from_dict(
1750
            construct_client_dict(self._client, data)
1751
        )
1752
1753
    @classmethod
1754
    def from_dict(cls, data) -> Guild:
1755
        """
1756
        Parameters
1757
        ----------
1758
        data : :class:`Dict`
1759
            Guild data received from the discord API.
1760
        Returns
1761
        -------
1762
        :class:`~pincer.objects.guild.guild.Guild`
1763
            The new guild object.
1764
        Raises
1765
        :class:`~pincer.exceptions.UnavailableGuildError`
1766
            The guild is unavailable due to a discord outage.
1767
        """
1768
        if data.get("unavailable", False):
1769
            raise UnavailableGuildError(
1770
                f"Guild \"{data['id']}\" is unavailable due to a discord"
1771
                " outage."
1772
            )
1773
1774
        return super().from_dict(data)
1775
1776
1777
@dataclass
1778
class UnavailableGuild(APIObject):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
1779
    id: Snowflake
1780
    unavailable: bool = True
1781