Passed
Pull Request — main (#275)
by
unknown
01:53
created

Guild.list_guild_members()   A

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 14
rs 10
c 0
b 0
f 0
cc 1
nop 3
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
coding-style introduced by
Too many lines in module (1775/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 ...exceptions import UnavailableGuildError
11
from ...utils.api_object import APIObject
12
from ...utils.conversion import construct_client_dict, remove_none
13
from ...utils.types import MISSING
14
15
if TYPE_CHECKING:
16
    from typing import Any, Dict, List, Optional, Tuple, Union
17
    from .channel import PublicThread, PrivateThread
18
19
    from .audit_log import AuditLog
20
    from .ban import Ban
21
    from .channel import Channel
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=data))
535
536
    async def modify_channel_positions(
537
            self, *channel: Dict[str, Optional[Union[int, bool, Snowflake]]]):
538
        """|coro|
539
        Create a new channel object for the guild.
540
541
        Parameters
542
        ----------
543
544
        \\*channel : Dict[str, Optional[Union[int, bool, :class:`~pincer.utils.snowflake.Snowflake`]
545
            Keys:
546
                - id : :class:`~pincer.utils.snowflake.Snowflake`
547
                - position : Optional[:class:`int`]
548
                - lock_permissions : Optional[:class:`bool`]
549
                - parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
550
551
        """
552
553
    async def list_active_threads(self) -> Tuple[
554
        List[Union[PublicThread, PrivateThread]], List[GuildMember]]:
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
555
        """|coro|
556
        Returns all active threads in the guild, including public and private threads.
557
        """
558
        data = await self._http.get(f"guilds/{self.id}/threads/active")
559
560
        threads = [Channel.from_dict(channel) for channel in data["threads"]]
561
        members = [GuildMember.from_dict(member) for member in data["members"]]
562
563
        return threads, members
564
565
    async def list_guild_members(self, limit: int = 1, after: int = 0):
566
        """|coro|
567
        Returns a list of guild member objects that are members of the guild.
568
569
        Parameters
570
        ----------
571
        limit : int
572
            max number of members to return (1-1000) |default| :data:`1`
573
        after : int
574
            the highest user id in the previous page |default| :data:`0`
575
        """
576
577
        return await self._http.get(
578
            f"guilds/{self.id}/members?limit={limit}&after={after}"
579
        )
580
581
    async def search_guild_members(self, query: str,
582
                                   limit: Optional[int] = None
583
                                   ) -> List[GuildMember]:
584
        """|coro|
585
        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...
586
587
        Parameters
588
        ----------
589
        query : str
590
            Query string to match username(s) and nickname(s) against.
591
        limit : Optional[int]
592
            max number of members to return (1-1000) |default| :data:`1`
593
594
        """
595
596
        data = await self._http.get(
597
            f"guilds/{id}/members/search?query={query}"
598
            f"&{limit}" if limit else ""
599
        )
600
601
        return [GuildMember.from_dict(member) for member in data]
602
603
    @overload
604
    async def add_guild_member(self, *, user_id: Snowflake,
605
                               access_token: str,
606
                               nick: Optional[str] = None,
607
                               roles: Optional[List[Snowflake]] = None,
608
                               mute: Optional[bool] = None,
609
                               deaf: Optional[bool] = None
610
                               ) -> Optional[GuildMember]:
611
        """|coro|
612
        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...
613
614
        Parameters
615
        ----------
616
        user_id : str
617
            id of the user to be added
618
        access_token : str
619
            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...
620
        nick : Optional[str]
621
        	value to set users nickname to
622
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
623
        	array of role ids the member is assigned
624
        mute : Optional[bool]
625
        	whether the user is muted in voice channels
626
        deaf : Optional[bool]
627
        	whether the user is deafened in voice channels
628
629
        Returns
630
        -------
631
        :class:`~pincer.objects.guild.member.GuildMember`
632
            If the user is not in the guild
633
        None
634
            If the user is in the guild
635
        """
636
637
    async def add_guild_member(self, user_id, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
638
        data = self._http.put(f"guilds/{self.id}/members/{user_id}",
639
                              data=kwargs)
640
641
        return GuildMember.from_dict(data) if data else None
642
643
    async def modify_current_member(self, nick: str) -> GuildMember:
644
        """|coro|
645
        Modifies the current member in a guild.
646
647
        Parameters
648
        ----------
649
        nick : str
650
            value to set users nickname to
651
        """
652
        data = self._http.patch(f"guilds/{self.id}/members/@me", {"nick": nick})
653
        member = GuildMember.from_dict(data)
654
        return member
655
656
    async def add_guild_member_role(self, user_id: int, role_id: int) -> None:
657
        """|coro|
658
        Adds a role to a guild member.
659
660
        Parameters
661
        ----------
662
        user_id : int
663
            id of the user to give a role to
664
        role_id : int
665
            id of a role
666
        """
667
        data = await self._http.put(
0 ignored issues
show
Unused Code introduced by
The variable data seems to be unused.
Loading history...
668
            f"guilds/{self.id}/{user_id}/roles/{role_id}", {})
669
        # 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...
670
671
    async def remove_guild_member_role(self, user_id: int,
672
                                       role_id: int) -> None:
673
        """|coro|
674
        Removes a role from a guild member.
675
676
        Parameters
677
        ----------
678
        user_id : int
679
            id of the user to remove a role from
680
        role_id : int
681
            id of a role
682
        """
683
        await self._http.delete(f"guilds/{self.id}/{user_id}/roles/{role_id}",
684
                                {})
685
        # 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...
686
687
    async def remove_guild_member(self, user_id: int) -> None:
688
        """|coro|
689
        Remove a member from a guild.
690
691
        Parameters
692
        ----------
693
        user_id : int
694
            id of the user to remove from the guild
695
        """
696
        await self._http.delete(f"guilds/{self.id}/members/{user_id}")
697
698
    async def ban(
699
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
700
        member_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
701
        reason: str = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
702
        delete_message_days: int = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
703
    ):
704
        """
705
        Parameters
706
        ----------
707
        member_id : :class:`int`
708
            ID of the guild member to ban.
709
        reason : Optional[:class:`str`]
710
            Reason for the kick.
711
        delete_message_days : Optional[:class:`int`]
712
            Number of days to delete messages for (0-7)
713
        """
714
        headers = {}
715
716
        if reason is not None:
717
            headers["X-Audit-Log-Reason"] = reason
718
719
        data = {}
720
721
        if delete_message_days is not None:
722
            data["delete_message_days"] = delete_message_days
723
724
        await self._http.put(
725
            f"/guilds/{self.id}/bans/{member_id}",
726
            data=data,
727
            headers=headers
728
        )
729
730
    async def kick(self, member_id: int, reason: Optional[str] = None):
731
        """|coro|
732
        Kicks a guild member.
733
        Parameters
734
        ----------
735
        member_id : :class:`int`
736
            ID of the guild member to kick.
737
        reason : Optional[:class:`str`]
738
            Reason for the kick.
739
        """
740
741
        headers = {}
742
743
        if reason is not None:
744
            headers["X-Audit-Log-Reason"] = reason
745
746
        await self._http.delete(
747
            f"/guilds/{self.id}/members/{member_id}",
748
            header=headers
749
        )
750
751
    async def get_roles(self) -> AsyncGenerator[Role, None]:
752
        """|coro|
753
        Fetches all the roles in the guild.
754
755
        Yields
756
        -------
757
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
758
            An async generator of Role objects.
759
        """
760
        data = await self._http.get(f"guilds/{self.id}/roles")
761
        for role_data in data:
762
            yield Role.from_dict(construct_client_dict(self._client, role_data))
763
764
    @overload
765
    async def create_role(
766
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
767
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
768
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
769
        name: Optional[str] = "new role",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
770
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
771
        color: Optional[int] = 0,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
772
        hoist: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
773
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
774
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
775
        mentionable: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
776
    ) -> Role:
777
        """|coro|
778
        Creates a new role for the guild.
779
        Requires the ``MANAGE_ROLES`` permission.
780
781
        Parameters
782
        ----------
783
        reason : Optional[:class:`str`]
784
            Reason for creating the role. |default| :data:`None`
785
        name : Optional[:class:`str`]
786
            name of the role |default| :data:`"new role"`
787
        permissions : Optional[:class:`str`]
788
            bitwise value of the enabled/disabled
789
            permissions, set to @everyone permissions
790
            by default |default| :data:`None`
791
        color : Optional[:class:`int`]
792
            RGB color value |default| :data:`0`
793
        hoist : Optional[:class:`bool`]
794
            whether the role should be displayed
795
            separately in the sidebar |default| :data:`False`
796
        icon : Optional[:class:`str`]
797
            the role's icon image (if the guild has
798
            the ``ROLE_ICONS`` feature) |default| :data:`None`
799
        unicode_emoji : Optional[:class:`str`]
800
            the role's unicode emoji as a standard emoji (if the guild
801
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
802
        mentionable : Optional[:class:`bool`]
803
            whether the role should be mentionable |default| :data:`False`
804
805
        Returns
806
        -------
807
        :class:`~pincer.objects.guild.role.Role`
808
            The new role object.
809
        """
810
        ...
811
812
    async def create_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
813
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
814
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
815
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
816
    ) -> Role:
817
        return Role.from_dict(
818
            construct_client_dict(
819
                self._client,
820
                await self._http.post(
821
                    f"guilds/{self.id}/roles",
822
                    data=kwargs,
823
                    headers=remove_none({"X-Audit-Log-Reason": reason})
824
                ),
825
            )
826
        )
827
828
    async def edit_role_position(
829
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
830
        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...
831
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
832
        position: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
833
    ) -> AsyncGenerator[Role, None]:
834
        """|coro|
835
        Edits the position of a role.
836
837
        Parameters
838
        ----------
839
        id : :class:`~pincer.utils.snowflake.Snowflake`
840
            The role ID
841
        reason : Optional[:class:`str`]
842
            Reason for editing the role position. |default| :data:`None`
843
        position : Optional[:class:`int`]
844
            Sorting position of the role |default| :data:`None`
845
846
        Yields
847
        -------
848
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
849
            An async generator of all of the guild's role objects.
850
        """
851
        data = await self._http.patch(
852
            f"guilds/{self.id}/roles",
853
            data={"id": id, "position": position},
854
            headers=remove_none({"X-Audit-Log-Reason": reason})
855
        )
856
        for role_data in data:
857
            yield Role.from_dict(construct_client_dict(self._client, role_data))
858
859
    @overload
860
    async def edit_role(
861
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
862
        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...
863
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
864
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
865
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
866
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
867
        color: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
868
        hoist: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
869
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
870
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
871
        mentionable: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
872
    ) -> Role:
873
        """|coro|
874
        Edits a role.
875
        Requires the ``MANAGE_ROLES`` permission.
876
877
        Parameters
878
        ----------
879
        id : :class:`~pincer.utils.snowflake.Snowflake`
880
            The role ID
881
        reason : Optional[:class:`str`]
882
            Reason for editing the role |default| :data:`None`
883
        name : Optional[:class:`str`]
884
            Name of the role |default| :data:`None`
885
        permissions : Optional[:class:`str`]
886
            Bitwise value of the enabled/disabled
887
            permissions |default| :data:`None`
888
        color : Optional[:class:`int`]
889
            RGB color value |default| :data:`None`
890
        hoist : Optional[:class:`bool`]
891
            Whether the role should be displayed
892
            separately in the sidebar |default| :data:`None`
893
        icon : Optional[:class:`str`]
894
            The role's icon image (if the guild has
895
            the ``ROLE_ICONS`` feature) |default| :data:`None`
896
        unicode_emoji : Optional[:class:`str`]
897
            The role's unicode emoji as a standard emoji (if the guild
898
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
899
        mentionable : Optional[:class:`bool`]
900
            Whether the role should be mentionable |default| :data:`None`
901
902
        Returns
903
        -------
904
        :class:`~pincer.objects.guild.role.Role`
905
            The edited role object.
906
        """
907
        ...
908
909
    async def edit_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
910
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
911
        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...
912
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
913
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
914
    ) -> Role:
915
        return Role.from_dict(
916
            construct_client_dict(
917
                self._client,
918
                await self._http.patch(
919
                    f"guilds/{self.id}/roles/{id}",
920
                    data=kwargs,
921
                    headers=remove_none({"X-Audit-Log-Reason": reason})
922
                ),
923
            )
924
        )
925
926
    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...
927
        """|coro|
928
        Deletes a role.
929
        Requires the `MANAGE_ROLES` permission.
930
931
        Parameters
932
        ----------
933
        id : :class:`~pincer.utils.snowflake.Snowflake`
934
            The role ID
935
        reason : Optional[:class:`str`]
936
            The reason for deleting the role |default| :data:`None`
937
        """
938
        await self._http.delete(
939
            f"guilds/{self.id}/roles/{id}",
940
            headers=remove_none({"X-Audit-Log-Reason": reason})
941
        )
942
943
    async def get_bans(self) -> AsyncGenerator[Ban, None]:
944
        """|coro|
945
        Fetches all the bans in the guild.
946
947
        Yields
948
        -------
949
        AsyncGenerator[:class:`~pincer.objects.guild.ban.Ban`, :data:`None`]
950
            An async generator of Ban objects.
951
        """
952
        data = await self._http.get(f"guilds/{self.id}/bans")
953
        for ban_data in data:
954
            yield Ban.from_dict(construct_client_dict(self._client, ban_data))
955
956
    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...
957
        """|coro|
958
        Fetches a ban from the guild.
959
960
        Parameters
961
        ----------
962
        id : :class:`~pincer.utils.snowflake.Snowflake`
963
            The user ID
964
965
        Returns
966
        -------
967
        :class:`~pincer.objects.guild.ban.Ban`
968
            The Ban object.
969
        """
970
        return Ban.from_dict(
971
            construct_client_dict(
972
                self._client,
973
                await self._http.get(f"guilds/{self.id}/bans/{id}"),
974
            )
975
        )
976
977
    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...
978
        """|coro|
979
        Unbans a user from the guild.
980
981
        Parameters
982
        ----------
983
        id : :class:`~pincer.utils.snowflake.Snowflake`
984
            The user ID
985
        reason : Optional[:class:`str`]
986
            The reason for unbanning the user |default| :data:`None`
987
        """
988
        await self._http.delete(
989
            f"guilds/{self.id}/bans/{id}",
990
            headers=remove_none({"X-Audit-Log-Reason": reason})
991
        )
992
993
    @overload
994
    async def edit(
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (20/15).
Loading history...
995
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
996
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
997
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
998
        region: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
999
        verification_level: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1000
        default_message_notifications: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1001
        explicit_content_filter: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1002
        afk_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1003
        afk_timeout: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1004
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1005
        owner_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1006
        splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1007
        discovery_splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1008
        banner: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1009
        system_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1010
        system_channel_flags: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1011
        rules_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1012
        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...
1013
        preferred_locale: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1014
        features: Optional[List[GuildFeature]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1015
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1016
    ) -> Guild:
1017
        """|coro|
1018
        Modifies the guild
1019
1020
        Parameters
1021
        ----------
1022
        name : Optional[:class:`str`]
1023
            Guild name |default| :data:`None`
1024
        region : Optional[:class:`str`]
1025
            Guild voice region ID |default| :data:`None`
1026
        verification_level : Optional[:class:`int`]
1027
            Verification level |default| :data:`None`
1028
        default_message_notifications : Optional[:class:`int`]
1029
            Default message notification level |default| :data:`None`
1030
        explicit_content_filter : Optional[:class:`int`]
1031
            Explicit content filter level |default| :data:`None`
1032
        afk_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1033
            ID for AFK channel |default| :data:`None`
1034
        afk_timeout : Optional[:class:`int`]
1035
            AFK timeout in seconds |default| :data:`None`
1036
        icon : Optional[:class:`str`]
1037
            base64 1024x1024 png/jpeg/gif image for the guild icon
1038
            (can be animated gif when the server
1039
            has the `ANIMATED_ICON` feature) |default| :data:`None`
1040
        owner_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1041
            User ID to transfer guild ownership to (must be owner) |default| :data:`None`
1042
        splash : Optional[:class:`str`]
1043
            base64 16:9 png/jpeg image for the guild splash (when the
1044
            server has the `INVITE_SPLASH` feature) |default| :data:`None`
1045
        discovery_splash : Optional[:class:`str`]
1046
            base64 16:9 png/jpeg image for the guild discovery splash
1047
            (when the server has the `DISCOVERABLE` feature) |default| :data:`None`
1048
        banner : Optional[:class:`str`]
1049
            base64 16:9 png/jpeg image for the guild banner (when the
1050
            server has the `BANNER` feature) |default| :data:`None`
1051
        system_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1052
            The ID of the channel where guild notices such as welcome
1053
            messages and boost events are posted |default| :data:`None`
1054
        system_channel_flags : Optional[:class:`int`]
1055
            System channel flags |default| :data:`None`
1056
        rules_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1057
            The ID of the channel where Community guilds display rules
1058
            and/or guidelines |default| :data:`None`
1059
        public_updates_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1060
            The ID of the channel where admins and moderators of
1061
            Community guilds receive notices from Discord |default| :data:`None`
1062
        preferred_locale : Optional[:class:`str`]
1063
            The preferred locale of a Community guild used in server
1064
            discovery and notices from Discord; defaults to "en-US" |default| :data:`None`
1065
        features : Optional[List[:class:`GuildFeature`]]
1066
            Enabled guild features |default| :data:`None`
1067
        description : Optional[:class:`str`]
1068
            The description for the guild, if the guild is discoverable |default| :data:`None`
1069
1070
        Returns
1071
        -------
1072
        :class:`~pincer.objects.guild.Guild`
1073
            The modified guild object.
1074
        """
1075
        ...
1076
1077
    async def edit(self, **kwargs) -> Guild:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
1078
        g = await self._http.patch(f"guilds/{self.id}", data=kwargs)
1079
        return Guild.from_dict(construct_client_dict(self._client, g))
1080
1081
    async def preview(self) -> GuildPreview:
1082
        """|coro|
1083
        Previews the guild.
1084
1085
        Returns
1086
        -------
1087
        :class:`~pincer.objects.guild.guild.GuildPreview`
1088
            The guild preview object.
1089
        """
1090
        data = await self._http.get(f"guilds/{self.id}/preview")
1091
        return GuildPreview.from_dict(data)
1092
1093
    async def delete(self):
1094
        """|coro|
1095
        Deletes the guild. Returns `204 No Content` on success.
1096
        """
1097
        await self._http.delete(f"guilds/{self.id}")
1098
1099
    async def prune_count(
1100
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1101
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1102
        include_roles: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1103
    ) -> int:
1104
        """|coro|
1105
        Returns the number of members that
1106
        would be removed in a prune operation.
1107
        Requires the ``KICK_MEMBERS`` permission.
1108
1109
        Parameters
1110
        ----------
1111
        days : Optional[:class:`int`]
1112
            Number of days to count prune for (1-30) |default| :data:`7`
1113
        include_roles : Optional[:class:`str`]
1114
            Comma-delimited array of Snowflakes;
1115
            role(s) to include |default| :data:`None`
1116
1117
        Returns
1118
        -------
1119
        :class:`int`
1120
            The number of members that would be removed.
1121
        """
1122
        return await self._http.get(
1123
            f"guilds/{self.id}/prune?{days=}&{include_roles=!s}"
1124
        )["pruned"]
1125
1126
    async def prune(
1127
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1128
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1129
        compute_prune_days: Optional[bool] = True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1130
        include_roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1131
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1132
    ) -> int:
1133
        """|coro|
1134
        Prunes members from the guild. Requires the ``KICK_MEMBERS`` permission.
1135
1136
        Parameters
1137
1138
        Parameters
1139
        ----------
1140
        days : Optional[:class:`int`]
1141
            Number of days to prune (1-30) |default| :data:`7`
1142
        compute_prune_days : Optional[:class:`bool`]
1143
            Whether ``pruned`` is returned, discouraged for large guilds
1144
            |default| :data:`True`
1145
        include_roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1146
            role(s) to include |default| :data:`None`
1147
        reason : Optional[:class:`str`]
1148
            Reason for the prune |default| :data:`None`
1149
1150
        Returns
1151
        -------
1152
        :class:`int`
1153
            The number of members that were removed.
1154
        """
1155
        return await self._http.post(
1156
            f"guilds/{self.id}/prune",
1157
            data={
1158
                "days": days,
1159
                "compute_prune_days": compute_prune_days,
1160
                "include_roles": include_roles
1161
            },
1162
            headers=remove_none({"X-Audit-Log-Reason": reason})
1163
        )["pruned"]
1164
1165
    async def get_voice_regions(self) -> AsyncGenerator[VoiceRegion, None]:
1166
        """|coro|
1167
        Returns an async generator of voice regions.
1168
1169
        Yields
1170
        -------
1171
        AsyncGenerator[:class:`~pincer.objects.voice.VoiceRegion`, :data:`None`]
1172
            An async generator of voice regions.
1173
        """
1174
        data = await self._http.get(f"guilds/{self.id}/regions")
1175
        for voice_region_data in data:
1176
            yield VoiceRegion.from_dict(construct_client_dict(self._client, voice_region_data))
1177
1178
    async def get_invites(self) -> AsyncGenerator[Invite, None]:
1179
        """|coro|
1180
        Returns an async generator of invites for the guild.
1181
        Requires the ``MANAGE_GUILD`` permission.
1182
1183
        Yields
1184
        -------
1185
        AsyncGenerator[:class:`~pincer.objects.invite.Invite`, :data:`None`]
1186
            An async generator of invites.
1187
        """
1188
        data = await self._http.get(f"guilds/{self.id}/invites")
1189
        for invite_data in data:
1190
            yield Invite.from_dict(construct_client_dict(self._client, invite_data))
1191
1192
    async def get_integrations(self) -> AsyncGenerator[Integration, None]:
1193
        """|coro|
1194
        Returns an async generator of integrations for the guild.
1195
        Requires the ``MANAGE_GUILD`` permission.
1196
1197
        Yields
1198
        -------
1199
        AsyncGenerator[:class:`~pincer.objects.integration.Integration`, :data:`None`]
1200
            An async generator of integrations.
1201
        """
1202
        data = await self._http.get(f"guilds/{self.id}/integrations")
1203
        for integration_data in data:
1204
            yield Integration.from_dict(construct_client_dict(self._client, integration_data))
1205
1206
    async def delete_integration(
1207
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1208
        integration: Integration,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1209
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1210
    ):
1211
        """|coro|
1212
        Deletes an integration.
1213
        Requires the ``MANAGE_GUILD`` permission.
1214
1215
        Parameters
1216
        ----------
1217
        integration : :class:`~pincer.objects.integration.Integration`
1218
            The integration to delete.
1219
        reason : Optional[:class:`str`]
1220
            Reason for the deletion |default| :data:`None`
1221
        """
1222
        await self._http.delete(
1223
            f"guilds/{self.id}/integrations/{integration.id}",
1224
            headers=remove_none({"X-Audit-Log-Reason": reason})
1225
        )
1226
1227
    async def get_widget_settings(self) -> GuildWidget:
1228
        """|coro|
1229
        Returns the guild widget settings.
1230
        Requires the ``MANAGE_GUILD`` permission.
1231
1232
        Returns
1233
        -------
1234
        :class:`~pincer.objects.guild.widget.GuildWidget`
1235
            The guild widget settings.
1236
        """
1237
        return GuildWidget.from_dict(
1238
            construct_client_dict(
1239
                self._client,
1240
                await self._http.get(f"guilds/{self.id}/widget")
1241
            )
1242
        )
1243
1244
    async def modify_widget(
1245
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1246
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1247
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1248
    ) -> GuildWidget:
1249
        """|coro|
1250
        Modifies the guild widget for the guild.
1251
        Requires the ``MANAGE_GUILD`` permission.
1252
1253
        Parameters
1254
        ----------
1255
        reason : Optional[:class:`str`]
1256
            Reason for the modification |default| :data:`None`
1257
        \\*\\*kwargs
1258
            The widget settings to modify
1259
1260
        Returns
1261
        -------
1262
        :class:`~pincer.objects.guild.widget.GuildWidget`
1263
            The updated GuildWidget object
1264
        """
1265
        data = await self._http.patch(
1266
            f"guilds/{self.id}/widget",
1267
            data=kwargs,
1268
            headers=remove_none({"X-Audit-Log-Reason": reason})
1269
        )
1270
        return GuildWidget.from_dict(construct_client_dict(self._client, data))
1271
1272
    async def get_widget(self) -> Dict[str, JSONSerializable]:
1273
        """|coro|
1274
        Returns the widget for the guild
1275
        """
1276
        return await self._http.get(f"guilds/{self.id}/widget.json")
1277
1278
    @property
1279
    async def vanity_url(self) -> Invite:
1280
        """|coro|
1281
        Returns the Vanity URL for the guild.
1282
        Requires the ``MANAGE_GUILD`` permission.
1283
        ``code`` will be null if a vanity URL has not been set.
1284
1285
        Returns
1286
        -------
1287
        :class:`~pincer.objects.guild.invite.Invite`
1288
            The vanity url for the guild.
1289
        """
1290
        data = await self._http.get(f"guilds/{self.id}/vanity-url")
1291
        return Invite.from_dict(construct_client_dict(self._client, data))
1292
1293
    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...
1294
        """|coro|
1295
        Returns a PNG image widget for the guild.
1296
        Requires no permissions or authentication.
1297
1298
        Widget Style Options
1299
        -------------------
1300
        * [``shield``](https://discord.com/api/guilds/81384788765712384/widget.png?style=shield)
1301
          shield style widget with Discord icon and guild members online count
1302
        * [``banner1``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner1)
1303
          large image with guild icon, name and online count.
1304
          "POWERED BY DISCORD" as the footer of the widget
1305
        * [``banner2``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner2)
1306
          smaller widget style with guild icon, name and online count.
1307
          Split on the right with Discord logo
1308
        * [``banner3``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner3)
1309
          large image with guild icon, name and online count.
1310
          In the footer, Discord logo on the
1311
          left and "Chat Now" on the right
1312
        * [``banner4``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner4)
1313
          large Discord logo at the top of the widget.
1314
          Guild icon, name and online count in the middle portion
1315
          of the widget and a "JOIN MY SERVER" button at the bottom
1316
1317
        Parameters
1318
        ----------
1319
        style : Optional[:class:`str`]
1320
            Style of the widget image returned |default| :data:`"shield"`
1321
1322
        Returns
1323
        -------
1324
        :class:`str`
1325
            A PNG image of the guild widget.
1326
        """
1327
        return await self._http.get(f"guilds/{self.id}/widget.png?{style=!s}")
1328
1329
    async def get_welcome_screen(self) -> WelcomeScreen:
1330
        """Returns the welcome screen for the guild.
1331
1332
        Returns
1333
        -------
1334
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1335
            The welcome screen for the guild.
1336
        """
1337
        data = await self._http.get(f"guilds/{self.id}/welcome-screen")
1338
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1339
1340
    async def modify_welcome_screen(
1341
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1342
        enabled: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1343
        welcome_channels: Optional[List[WelcomeScreenChannel]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1344
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1345
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1346
    ) -> WelcomeScreen:
1347
        """|coro|
1348
        Modifies the guild's Welcome Screen.
1349
        Requires the ``MANAGE_GUILD`` permission.
1350
1351
        Parameters
1352
        ----------
1353
        enabled : Optional[:class:`bool`]
1354
            Whether the welcome screen is enabled |default| :data:`None`
1355
        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...
1356
            Channels linked in the welcome screen and
1357
            their display options |default| :data:`None`
1358
        description : Optional[:class:`str`]
1359
            The server description to show
1360
            in the welcome screen |default| :data:`None`
1361
        reason : Optional[:class:`str`]
1362
            Reason for the modification |default| :data:`None`
1363
1364
        Returns
1365
        -------
1366
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1367
            The updated WelcomeScreen object
1368
        """
1369
        data = await self._http.patch(
1370
            f"guilds/{self.id}/welcome-screen",
1371
            data={
1372
                "enabled": enabled,
1373
                "welcome_channels": welcome_channels,
1374
                "description": description
1375
            },
1376
            headers=remove_none({"X-Audit-Log-Reason": reason})
1377
        )
1378
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1379
1380
    async def modify_current_user_voice_state(
1381
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1382
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1383
        suppress: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1384
        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...
1385
    ):
1386
        """|coro|
1387
        Updates the current user's voice state.
1388
1389
        There are currently several caveats for this endpoint:
1390
        * ``channel_id`` must currently point to a stage channel
1391
        * current user must already have joined ``channel_id``
1392
        * You must have the ``MUTE_MEMBERS`` permission to
1393
          unsuppress yourself. You can always suppress yourself.
1394
        * You must have the ``REQUEST_TO_SPEAK`` permission to request
1395
          to speak. You can always clear your own request to speak.
1396
        * You are able to set ``request_to_speak_timestamp`` to any
1397
          present or future time.
1398
1399
        Parameters
1400
        ----------
1401
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1402
            The ID of the channel the user is currently in
1403
        suppress : Optional[:class:`bool`]
1404
            Toggles the user's suppress state |default| :data:`None`
1405
        request_to_speak_timestamp : Optional[:class:`~pincer.utils.timestamp.Timestamp`]
1406
            Sets the user's request to speak
1407
        """
1408
        await self._http.patch(
1409
            f"guilds/{self.id}/voice-states/@me",
1410
            data={
1411
                "channel_id": channel_id,
1412
                "suppress": suppress,
1413
                "request_to_speak_timestamp": request_to_speak_timestamp
1414
            }
1415
        )
1416
1417
    async def modify_user_voice_state(
1418
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1419
        user: User,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1420
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1421
        suppress: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1422
    ):
1423
        """|coro|
1424
        Updates another user's voice state.
1425
1426
        There are currently several caveats for this endpoint:
1427
        * ``channel_id`` must currently point to a stage channel
1428
        * User must already have joined ``channel_id``
1429
        * You must have the ``MUTE_MEMBERS`` permission.
1430
          (Since suppression is the only thing that is available currently.)
1431
        * When unsuppressed, non-bot users will have their
1432
          ``request_to_speak_timestamp`` set to the current time.
1433
          Bot users will not.
1434
        * When suppressed, the user will have their
1435
          ``request_to_speak_timestamp`` removed.
1436
1437
        Parameters
1438
        ----------
1439
        user : :class:`~pincer.objects.guild.member.Member`
1440
            The user to update
1441
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1442
            The ID of the channel the user is currently in
1443
        suppress : Optional[:class:`bool`]
1444
            Toggles the user's suppress state |default| :data:`None`
1445
        """
1446
        await self._http.patch(
1447
            f"guilds/{self.id}/voice-states/{user.id}",
1448
            data={
1449
                "channel_id": channel_id,
1450
                "suppress": suppress
1451
            }
1452
        )
1453
1454
    async def get_audit_log(self) -> AuditLog:
1455
        """|coro|
1456
        Returns an audit log object for the guild.
1457
        Requires the ``VIEW_AUDIT_LOG`` permission.
1458
1459
        Returns
1460
        -------
1461
        :class:`~pincer.objects.guild.audit_log.AuditLog`
1462
            The audit log object for the guild.
1463
        """
1464
        return AuditLog.from_dict(
1465
            construct_client_dict(
1466
                self._client,
1467
                await self._http.get(f"guilds/{self.id}/audit-logs")
1468
            )
1469
        )
1470
1471
    async def get_emojis(self) -> AsyncGenerator[Emoji, None]:
1472
        """|coro|
1473
        Returns an async generator of the emojis in the guild.
1474
1475
        Yields
1476
        ------
1477
        :class:`~pincer.objects.guild.emoji.Emoji`
1478
            The emoji object.
1479
        """
1480
        data = await self._http.get(f"guilds/{self.id}/emojis")
1481
        for emoji_data in data:
1482
            yield Emoji.from_dict(
1483
                construct_client_dict(self._client, emoji_data)
1484
            )
1485
1486
    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...
1487
        """|coro|
1488
        Returns an emoji object for the given ID.
1489
1490
        Parameters
1491
        ----------
1492
        id : :class:`~pincer.utils.snowflake.Snowflake`
1493
            The ID of the emoji
1494
1495
        Returns
1496
        -------
1497
        :class:`~pincer.objects.guild.emoji.Emoji`
1498
            The emoji object.
1499
        """
1500
        return Emoji.from_dict(
1501
            construct_client_dict(
1502
                self._client,
1503
                await self._http.get(f"guilds/{self.id}/emojis/{id}")
1504
            )
1505
        )
1506
1507
    async def create_emoji(
1508
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1509
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1510
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1511
        image: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1512
        roles: List[Snowflake],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1513
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1514
    ) -> Emoji:
1515
        """|coro|
1516
        Creates a new emoji for the guild.
1517
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1518
1519
        Emojis and animated emojis have a maximum file size of 256kb.
1520
        Attempting to upload an emoji larger than this limit will fail.
1521
1522
        Parameters
1523
        ----------
1524
        name : :class:`str`
1525
            Name of the emoji
1526
        image : :class:`str`
1527
            The 128x128 emoji image data
1528
        roles : List[:class:`~pincer.utils.snowflake.Snowflake`]
1529
            Roles allowed to use this emoji
1530
        reason : Optional[:class:`str`]
1531
            The reason for creating the emoji |default| :data:`None`
1532
1533
        Returns
1534
        -------
1535
        :class:`~pincer.objects.guild.emoji.Emoji`
1536
            The newly created emoji object.
1537
        """
1538
        data = await self._http.post(
1539
            f"guilds/{self.id}/emojis",
1540
            data={
1541
                "name": name,
1542
                "image": image,
1543
                "roles": roles
1544
            },
1545
            headers=remove_none({"X-Audit-Log-Reason": reason})
1546
        )
1547
        return Emoji.from_dict(
1548
            construct_client_dict(self._client, data)
1549
        )
1550
1551
    async def edit_emoji(
1552
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1553
        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...
1554
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1555
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1556
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1557
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1558
    ) -> Emoji:
1559
        """|coro|
1560
        Modifies the given emoji.
1561
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1562
1563
        Parameters
1564
        ----------
1565
        id : :class:`~pincer.utils.snowflake.Snowflake`
1566
            The ID of the emoji
1567
        name : Optional[:class:`str`]
1568
            Name of the emoji |default| :data:`None`
1569
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1570
            Roles allowed to use this emoji |default| :data:`None`
1571
        reason : Optional[:class:`str`]
1572
            The reason for editing the emoji |default| :data:`None`
1573
1574
        Returns
1575
        -------
1576
        :class:`~pincer.objects.guild.emoji.Emoji`
1577
            The modified emoji object.
1578
        """
1579
        data = await self._http.patch(
1580
            f"guilds/{self.id}/emojis/{id}",
1581
            data={
1582
                "name": name,
1583
                "roles": roles
1584
            },
1585
            headers=remove_none({"X-Audit-Log-Reason": reason})
1586
        )
1587
        return Emoji.from_dict(
1588
            construct_client_dict(self._client, data)
1589
        )
1590
1591
    async def delete_emoji(
1592
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1593
        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...
1594
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1595
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1596
    ):
1597
        """|coro|
1598
        Deletes the given emoji.
1599
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1600
1601
        Parameters
1602
        ----------
1603
        id : :class:`~pincer.utils.snowflake.Snowflake`
1604
            The ID of the emoji
1605
        reason : Optional[:class:`str`]
1606
            The reason for deleting the emoji |default| :data:`None`
1607
        """
1608
        await self._http.delete(
1609
            f"guilds/{self.id}/emojis/{id}",
1610
            headers=remove_none({"X-Audit-Log-Reason": reason})
1611
        )
1612
1613
    async def get_templates(self) -> AsyncGenerator[GuildTemplate, None]:
1614
        """|coro|
1615
        Returns an async generator of the guild templates.
1616
1617
        Yields
1618
        -------
1619
        AsyncGenerator[:class:`~pincer.objects.guild.template.GuildTemplate`, :data:`None`]
1620
            The guild template object.
1621
        """
1622
        data = await self._http.get(f"guilds/{self.id}/templates")
1623
        for template_data in data:
1624
            yield GuildTemplate.from_dict(
1625
                construct_client_dict(self._client, template_data)
1626
            )
1627
1628
    async def create_template(
1629
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1630
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1631
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1632
    ) -> GuildTemplate:
1633
        """|coro|
1634
        Creates a new template for the guild.
1635
        Requires the ``MANAGE_GUILD`` permission.
1636
1637
        Parameters
1638
        ----------
1639
        name : :class:`str`
1640
            Name of the template (1-100 characters)
1641
        description : Optional[:class:`str`]
1642
            Description of the template
1643
            (0-120 characters) |default| :data:`None`
1644
        Returns
1645
        -------
1646
        :class:`~pincer.objects.guild.template.GuildTemplate`
1647
            The newly created template object.
1648
        """
1649
        data = await self._http.post(
1650
            f"guilds/{self.id}/templates",
1651
            data={
1652
                "name": name,
1653
                "description": description
1654
            }
1655
        )
1656
        return GuildTemplate.from_dict(
1657
            construct_client_dict(self._client, data)
1658
        )
1659
1660
    async def sync_template(
1661
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1662
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1663
    ) -> GuildTemplate:
1664
        """|coro|
1665
        Syncs the given template.
1666
        Requires the ``MANAGE_GUILD`` permission.
1667
1668
        Parameters
1669
        ----------
1670
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1671
            The template to sync
1672
1673
        Returns
1674
        -------
1675
        :class:`~pincer.objects.guild.template.GuildTemplate`
1676
            The synced template object.
1677
        """
1678
        data = await self._http.put(
1679
            f"guilds/{self.id}/templates/{template.code}"
1680
        )
1681
        return GuildTemplate.from_dict(
1682
            construct_client_dict(self._client, data)
1683
        )
1684
1685
    async def edit_template(
1686
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1687
        template: GuildTemplate,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1688
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1689
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1690
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1691
    ) -> GuildTemplate:
1692
        """|coro|
1693
        Modifies the template's metadata.
1694
        Requires the ``MANAGE_GUILD`` permission.
1695
1696
        Parameters
1697
        ----------
1698
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1699
            The template to edit
1700
        name : Optional[:class:`str`]
1701
            Name of the template (1-100 characters)
1702
            |default| :data:`None`
1703
        description : Optional[:class:`str`]
1704
            Description of the template (0-120 characters)
1705
            |default| :data:`None`
1706
1707
        Returns
1708
        -------
1709
        :class:`~pincer.objects.guild.template.GuildTemplate`
1710
            The edited template object.
1711
        """
1712
        data = await self._http.patch(
1713
            f"guilds/{self.id}/templates/{template.code}",
1714
            data={
1715
                "name": name,
1716
                "description": description
1717
            }
1718
        )
1719
        return GuildTemplate.from_dict(
1720
            construct_client_dict(self._client, data)
1721
        )
1722
1723
    async def delete_template(
1724
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1725
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1726
    ) -> GuildTemplate:
1727
        """|coro|
1728
        Deletes the given template.
1729
        Requires the ``MANAGE_GUILD`` permission.
1730
1731
        Parameters
1732
        ----------
1733
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1734
            The template to delete
1735
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1736
        Returns
1737
        -------
1738
        :class:`~pincer.objects.guild.template.GuildTemplate`
1739
            The deleted template object.
1740
        """
1741
        data = await self._http.delete(
1742
            f"guilds/{self.id}/templates/{template.code}"
1743
        )
1744
        return GuildTemplate.from_dict(
1745
            construct_client_dict(self._client, data)
1746
        )
1747
1748
    @classmethod
1749
    def from_dict(cls, data) -> Guild:
1750
        """
1751
        Parameters
1752
        ----------
1753
        data : :class:`Dict`
1754
            Guild data received from the discord API.
1755
        Returns
1756
        -------
1757
        :class:`~pincer.objects.guild.guild.Guild`
1758
            The new guild object.
1759
        Raises
1760
        :class:`~pincer.exceptions.UnavailableGuildError`
1761
            The guild is unavailable due to a discord outage.
1762
        """
1763
        if data.get("unavailable", False):
1764
            raise UnavailableGuildError(
1765
                f"Guild \"{data['id']}\" is unavailable due to a discord"
1766
                " outage."
1767
            )
1768
1769
        return super().from_dict(data)
1770
1771
1772
@dataclass
1773
class UnavailableGuild(APIObject):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
1774
    id: Snowflake
1775
    unavailable: bool = True
1776