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

Guild.add_guild_member()   A

Complexity

Conditions 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 2
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 (1827/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 .invite import Invite
11
from .channel import Channel
12
from ..message.emoji import Emoji
13
from ..message.file import File
14
from ...exceptions import UnavailableGuildError
15
from ...utils.api_object import APIObject
16
from ...utils.conversion import construct_client_dict, remove_none
17
from ...utils.types import MISSING
18
19
20
if TYPE_CHECKING:
21
    from typing import Any, Dict, List, Optional, Tuple, Union, Generator
22
    from .channel import PublicThread, PrivateThread, ChannelType
23
24
    from .audit_log import AuditLog
25
    from .ban import Ban
26
    from .member import GuildMember
27
    from .features import GuildFeature
28
    from .overwrite import Overwrite
29
    from .role import Role
30
    from .stage import StageInstance
31
    from .template import GuildTemplate
32
    from .welcome_screen import WelcomeScreen, WelcomeScreenChannel
33
    from .widget import GuildWidget
34
    from .webhook import Webhook
35
    from ..user.user import User
36
    from ..user.integration import Integration
37
    from ..voice.region import VoiceRegion
38
    from ..events.presence import PresenceUpdateEvent
39
    from ..message.sticker import Sticker
40
    from ..user.voice_state import VoiceState
41
    from ...client import Client
42
    from ...utils.timestamp import Timestamp
43
    from ...utils.types import APINullable, JSONSerializable
44
    from ...utils.snowflake import Snowflake
45
46
47
class PremiumTier(IntEnum):
48
    """Represents the boost tier of a guild.
49
    Attributes
50
    ----------
51
    NONE:
52
        Guild has not unlocked any Server Boost perks.
53
    TIER_1:
54
        Guild has unlocked Server Boost level 1 perks.
55
    TIER_2:
56
        Guild has unlocked Server Boost level 2 perks.
57
    TIER_3:
58
        Guild has unlocked Server Boost level 3 perks.
59
    """
60
61
    NONE = 0
62
    TIER_1 = 1
63
    TIER_2 = 2
64
    TIER_3 = 3
65
66
67
class GuildNSFWLevel(IntEnum):
68
    """Represents the NSFW level of a guild.
69
    Attributes
70
    ----------
71
    DEFAULT:
72
        Default NSFW level.
73
    EXPLICIT:
74
        Explicit NSFW level.
75
    SAFE:
76
        SAFE NSFW level.
77
    AGE_RESTRICTED:
78
        Age restricted NSFW level.
79
    """
80
81
    DEFAULT = 0
82
    EXPLICIT = 1
83
    SAFE = 2
84
    AGE_RESTRICTED = 3
85
86
87
class ExplicitContentFilterLevel(IntEnum):
88
    """Represents the filter content level of a guild.
89
    Attributes
90
    ----------
91
    DISABLED:
92
        Media content will not be scanned.
93
    MEMBERS_WITHOUT_ROLES:
94
        Media content sent by members without roles will be scanned.
95
    ALL_MEMBERS:
96
        Media content sent by all members will be scanned.
97
    """
98
99
    DISABLED = 0
100
    MEMBERS_WITHOUT_ROLES = 1
101
    ALL_MEMBERS = 2
102
103
104
class MFALevel(IntEnum):
105
    """Represents the multi factor authentication level of a guild.
106
    Attributes
107
    ----------
108
    NONE:
109
        Guild has no MFA/2FA requirement for moderation actions.
110
    ELEVATED:
111
        Guild has a 2FA requirement for moderation actions
112
    """
113
114
    NONE = 0
115
    ELEVATED = 1
116
117
118
class VerificationLevel(IntEnum):
119
    """Represents the verification level of a guild.
120
    Attributes
121
    ----------
122
    NONE:
123
        Unrestricted.
124
    LOW:
125
        Must have verified email on account.
126
    MEDIUM:
127
        Must be registered on Discord for longer than 5 minutes.
128
    HIGH:
129
        Must be a member of the server for longer than 10 minutes.
130
    VERY_HIGH:
131
        Must have a verified phone number.
132
    """
133
134
    NONE = 0
135
    LOW = 1
136
    MEDIUM = 2
137
    HIGH = 3
138
    VERY_HIGH = 4
139
140
141
class DefaultMessageNotificationLevel(IntEnum):
142
    """Represents the default message notification level of a guild.
143
    Attributes
144
    ----------
145
    ALL_MESSAGES:
146
        Members will receive notifications for all messages by default.
147
    ONLY_MENTIONS:
148
        Members will receive notifications only for messages that @mention them by default.
149
    """
150
151
    # noqa: E501
152
    ALL_MESSAGES = 0
153
    ONLY_MENTIONS = 1
154
155
156
class SystemChannelFlags(IntEnum):
157
    """Represents the system channel flags of a guild.
158
    Attributes
159
    ----------
160
    SUPPRESS_JOIN_NOTIFICATIONS:
161
        Suppress member join notifications.
162
    SUPPRESS_PREMIUM_SUBSCRIPTIONS:
163
        Suppress server boost notifications.
164
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS:
165
        Suppress server setup tips.
166
    SUPPRESS_JOIN_NOTIFICATION_REPLIES:
167
        Hide member join sticker reply buttons
168
    """
169
170
    SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0
171
    SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
172
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS = 1 << 2
173
    SUPPRESS_JOIN_NOTIFICATION_REPLIES = 1 << 3
174
175
176
@dataclass(repr=False)
177
class GuildPreview(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (10/7)
Loading history...
178
    """Represents a guild preview.
179
    Attributes
180
    ----------
181
    id: :class:`Snowflake`
182
        The guild ID.
183
    name: :class:`str`
184
        The guild name.
185
    icon: :class:`str`
186
        The guild icon hash.
187
    splash: :class:`str`
188
        The guild splash hash.
189
    discovery_splash: :class:`str`
190
        The guild discovery splash hash.
191
    emojis: :class:`List[Emoji]`
192
        The guild emojis.
193
    features: :class:`List[GuildFeature]`
194
        The guild features.
195
    approximate_member_count: :class:`int`
196
        The approximate member count.
197
    approximate_presence_count: :class:`int`
198
        The approximate number of online members in this guild
199
    description: :class:`str`
200
        The guild description.
201
    """
202
203
    id: Snowflake
204
    name: str
205
    emojis: List[Emoji]
206
    features: List[GuildFeature]
207
    approximate_member_count: int
208
    approximate_presence_count: int
209
210
    icon: APINullable[str] = MISSING
211
    splash: APINullable[str] = MISSING
212
    discovery_splash: APINullable[str] = MISSING
213
    description: APINullable[str] = MISSING
214
215
216
@dataclass(repr=False)
217
class Guild(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (59/7)
Loading history...
best-practice introduced by
Too many public methods (54/20)
Loading history...
218
    """Represents a Discord guild/server in which your client resides.
219
    Attributes
220
    ----------
221
    afk_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
222
        Id of afk channel
223
    afk_timeout: :class:`int`
224
        Afk timeout in seconds
225
    application_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
226
        Application id of the guild creator if it is bot-created
227
    banner: Optional[:class:`str`]
228
        Banner hash
229
    default_message_notifications: :class:`~pincer.objects.guild.guild.DefaultMessageNotificationLevel`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

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

Loading history...
230
        Default message notifications level
231
    description: Optional[:class:`str`]
232
        The description of a Community guild
233
    discovery_splash: Optional[:class:`str`]
234
        Discovery splash hash;
235
        only present for guilds with the "DISCOVERABLE" feature
236
    emojis: List[:class:`~pincer.objects.message.emoji.Emoji`]
237
        Custom guild emojis
238
    explicit_content_filter: :class:`~pincer.objects.guild.guild.ExplicitContentFilterLevel`
239
        Explicit content filter level
240
    features: List[:class:`~pincer.objects.guild.features.GuildFeature`]
241
        Enabled guild features
242
    id: :class:`~pincer.utils.snowflake.Snowflake`
243
        Guild id
244
    icon: Optional[:class:`str`]
245
        Icon hash
246
    mfa_level: :class:`~pincer.objects.guild.guild.MFALevel`
247
        Required MFA level for the guild
248
    name: :class:`str`
249
        Guild name (2-100 characters, excluding trailing and leading
250
        whitespace)
251
    nsfw_level: :class:`~pincer.objects.guild.guild.NSFWLevel`
252
        Guild NSFW level
253
    owner_id: :class:`~pincer.utils.snowflake.Snowflake`
254
        Id of owner
255
    preferred_locale: :class:`str`
256
        The preferred locale of a Community guild;
257
        used in server discovery and notices from Discord;
258
        defaults to "en-US"
259
    premium_tier: :class:`~pincer.objects.guild.guild.PremiumTier`
260
        Premium tier (Server Boost level)
261
    public_updates_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
262
        The id of the channel where admins
263
        and moderators of Community guilds receive notices from Discord
264
    roles: List[:class:`~pincer.objects.guild.role.Role`]
265
        Roles in the guild
266
    rules_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
267
        The id of the channel where Community guilds can display rules
268
        and/or guidelines
269
    splash: Optional[:class:`str`]
270
        Splash hash
271
    system_channel_flags: :class:`~pincer.objects.guild.guild.SystemChannelFlags`
272
        System channel flags
273
    system_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
274
        The id of the channel where guild notices
275
        such as welcome messages and boost events are posted
276
    vanity_url_code: Optional[:class:`str`]
277
        The vanity url code for the guild
278
    verification_level: :class:`~pincer.objects.guild.guild.VerificationLevel`
279
        Verification level required for the guild
280
    approximate_member_count: APINullable[:class:`int`]
281
        Approximate number of members in this guild, returned from the
282
        `GET /guilds/<id>` endpoint when with_counts is true
283
    approximate_presence_count: APINullable[:class:`int`]
284
        Approximate number of non-offline members in this guild,
285
        returned from the `GET /guilds/<id>`
286
        endpoint when with_counts is true
287
    channels: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
288
        Channels in the guild
289
    icon_hash: APINullable[Optional[:class:`str`]]
290
        Icon hash, returned when in the template object
291
    joined_at: APINullable[:class:`~pincer.utils.timestamp.Timestamp`]
292
        When this guild was joined at
293
    large: APINullable[:class:`bool`]
294
        True if this is considered a large guild
295
    max_members: APINullable[:class:`int`]
296
        The maximum number of members for the guild
297
    max_presences: APINullable[Optional[:class:`int`]]
298
        The maximum number of presences for the guild
299
        (null is always returned, apart from the largest of guilds)
300
    max_video_channel_users: APINullable[:class:`int`]
301
        The maximum amount of users in a video channel
302
    members: APINullable[List[:class:`~pincer.objects.guild.member.GuildMember`]]
303
        Users in the guild
304
    member_count: APINullable[:class:`bool`]
305
        Total number of members in this guild
306
    nsfw: APINullable[:class:`bool`]
307
        Boolean if the server is NSFW
308
    owner: APINullable[:class:`bool`]
309
        True if the user is the owner of the guild
310
    permissions: APINullable[:class:`str`]
311
        Total permissions for the user in the guild
312
        (excludes overwrites)
313
    premium_subscription_count: APINullable[:class:`int`]
314
        The number of boosts this guild currently has
315
    presences: APINullable[List[:class:`~pincer.objects.events.presence.PresenceUpdateEvent`]]
316
        Presences of the members in the guild,
317
        will only include non-offline members if the size is greater
318
        than large threshold
319
    stage_instances: APINullable[List[:class:`~pincer.objects.guild.stage.StageInstance`]]
320
        Stage instances in the guild
321
    stickers: Optional[List[:class:`~pincer.objects.message.sticker.Sticker`]]
322
        Custom guild stickers
323
    region: APINullable[Optional[:class:`str`]]
324
        Voice region id for the guild (deprecated)
325
    threads: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
326
        All active threads in the guild that current user
327
        has permission to view
328
    unavailable: APINullable[:class:`bool`]
329
        True if this guild is unavailable due to an outage
330
    voice_states: APINullable[List[:class:`~pincer.objects.user.voice_state.VoiceState`]]
331
        States of members currently in voice channels;
332
        lacks the guild_id key
333
    widget_enabled: APINullable[:class:`bool`]
334
        True if the server widget is enabled
335
    widget_channel_id: APINullable[Optional[:class:`~pincer.utils.snowflake.Snowflake`]]
336
        The channel id that the widget will generate an invite to,
337
        or null if set to no invite
338
    welcome_screen: APINullable[:class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`]
339
        The welcome screen of a Community guild, shown to new members,
340
        returned in an Invite's guild object
341
    """
342
343
    # noqa: E501
344
    features: List[GuildFeature]
345
    id: Snowflake
346
    name: str
347
    nsfw_level: GuildNSFWLevel
348
    verification_level: VerificationLevel
349
350
    # Guild invites missing
351
    system_channel_flags: APINullable[SystemChannelFlags] = MISSING
352
    explicit_content_filter: APINullable[ExplicitContentFilterLevel] = MISSING
353
    premium_tier: APINullable[PremiumTier] = MISSING
354
    default_message_notifications: APINullable[DefaultMessageNotificationLevel] = MISSING
355
    mfa_level: APINullable[MFALevel] = MISSING
356
    owner_id: APINullable[Snowflake] = MISSING
357
    afk_timeout: APINullable[int] = MISSING
358
    emojis: APINullable[List[Emoji]] = MISSING
359
    preferred_locale: APINullable[str] = MISSING
360
    roles: APINullable[List[Role]] = MISSING
361
362
    guild_scheduled_events: APINullable[List] = MISSING
363
    lazy: APINullable[bool] = MISSING
364
    premium_progress_bar_enabled: APINullable[bool] = MISSING
365
    guild_hashes: APINullable[Dict] = MISSING
366
    afk_channel_id: APINullable[Snowflake] = MISSING
367
    application_id: APINullable[Snowflake] = MISSING
368
    embedded_activities: APINullable[List] = MISSING
369
    banner: APINullable[str] = MISSING
370
    description: APINullable[str] = MISSING
371
    discovery_splash: APINullable[str] = MISSING
372
    icon: APINullable[str] = MISSING
373
    public_updates_channel_id: APINullable[Snowflake] = MISSING
374
    rules_channel_id: APINullable[Snowflake] = MISSING
375
    splash: APINullable[str] = MISSING
376
    system_channel_id: APINullable[Snowflake] = MISSING
377
    vanity_url_code: APINullable[str] = MISSING
378
379
    application_command_counts: APINullable[Dict] = MISSING
380
    application_command_count: APINullable[int] = MISSING
381
    approximate_member_count: APINullable[int] = MISSING
382
    approximate_presence_count: APINullable[int] = MISSING
383
    channels: APINullable[List[Channel]] = field(default_factory=list)
384
    # TODO: Add type when type is known
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
385
    hub_type: APINullable[Any] = MISSING
386
    icon_hash: APINullable[Optional[str]] = MISSING
387
    joined_at: APINullable[Timestamp] = MISSING
388
    large: APINullable[bool] = MISSING
389
    max_members: APINullable[int] = MISSING
390
    max_presences: APINullable[Optional[int]] = MISSING
391
    max_video_channel_users: APINullable[int] = MISSING
392
    members: APINullable[List[GuildMember]] = MISSING
393
    member_count: APINullable[bool] = MISSING
394
    nsfw: APINullable[bool] = MISSING
395
    # Note: This is missing from discord's docs but in the api
396
    owner: APINullable[bool] = MISSING
397
    permissions: APINullable[str] = MISSING
398
    premium_subscription_count: APINullable[int] = MISSING
399
    presences: APINullable[List[PresenceUpdateEvent]] = MISSING
400
    stage_instances: APINullable[List[StageInstance]] = MISSING
401
    stickers: APINullable[List[Sticker]] = MISSING
402
    region: APINullable[Optional[str]] = MISSING
403
    threads: APINullable[List[Channel]] = MISSING
404
    # Guilds are considered available unless otherwise specified
405
    unavailable: APINullable[bool] = False
406
    voice_states: APINullable[List[VoiceState]] = MISSING
407
    widget_enabled: APINullable[bool] = MISSING
408
    widget_channel_id: APINullable[Optional[Snowflake]] = MISSING
409
    welcome_screen: APINullable[WelcomeScreen] = MISSING
410
411
    @classmethod
412
    async def from_id(cls, client: Client, _id: Union[int, Snowflake]) -> Guild:
413
        """
414
        Parameters
415
        ----------
416
        client : :class:`~pincer.Client`
417
            Client object to use the http gateway from.
418
        _id : :class:`pincer.utils.snowflake.Snowflake`
419
            Guild ID.
420
        Returns
421
        -------
422
        :class:`~pincer.objects.guild.guild.Guild`
423
            The new guild object.
424
        """
425
        data = await client.http.get(f"/guilds/{_id}")
426
        channel_data = await client.http.get(f"/guilds/{_id}/channels")
427
428
        data["channels"]: List[Channel] = [
429
            Channel.from_dict(construct_client_dict(client, i))
430
            for i in (channel_data or [])
431
        ]
432
433
        return Guild.from_dict(construct_client_dict(client, data))
434
435
    async def get_member(self, _id: int) -> GuildMember:
436
        """|coro|
437
        Fetches a GuildMember from its identifier
438
439
        Parameters
440
        ----------
441
        _id: int
442
            The id of the guild member which should be fetched from the Discord
443
            gateway.
444
        Returns
445
        -------
446
        :class:`~pincer.objects.guild.member.GuildMember`
447
            A GuildMember object.
448
        """
449
        return await GuildMember.from_id(self._client, self.id, _id)
450
451
    @overload
452
    async def modify_member(
453
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
454
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
455
        _id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
456
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
457
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
458
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
459
        deaf: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
460
        channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
461
    ) -> GuildMember:
462
        """|coro|
463
        Modifies a member in the guild from its identifier and based on the
464
        keyword arguments provided.
465
        Parameters
466
        ----------
467
        _id : int
468
            Id of the member to modify
469
        nick : Optional[:class:`str`]
470
            New nickname for the member |default| :data:`None`
471
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake]]
472
            New roles for the member |default| :data:`None`
473
        mute : Optional[:class:`bool`]
474
            Whether the member is muted |default| :data:`None`
475
        deaf : Optional[:class:`bool`]
476
            Whether the member is deafened |default| :data:`None`
477
        channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake]
478
            Voice channel id to move to |default| :data:`None`
479
        Returns
480
        -------
481
        :class:`~pincer.objects.guild.member.GuildMember`
482
            The new member object.
483
        """
484
        ...
485
486
    async def modify_member(self, _id: int, **kwargs) -> GuildMember:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
487
        data = await self._http.patch(
488
            f"guilds/{self.id}/members/{_id}", data=kwargs
489
        )
490
        return GuildMember.from_dict(construct_client_dict(self._client, data))
491
492
      
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
493
    @overload
494
    async def create_channel(
0 ignored issues
show
best-practice introduced by
Too many arguments (11/5)
Loading history...
495
        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...
496
        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...
497
        type: Optional[ChannelType] = 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...
498
        topic: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
499
        bitrate: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
500
        user_limit: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
501
        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...
502
        position: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
503
        permission_overwrites: Optional[List[Overwrite]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
504
        parent_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
505
        nsfw: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
506
    ) -> Channel:
507
        """|coro|
508
        Create a new channel object for the guild.
509
510
        Parameters
511
        ----------
512
        name : str
513
            channel name (1-100 characters)
514
        type : Optional[:class:int`]
515
            the type of channel
516
        topic : Optional[:class:str`]
517
            channel topic (0-1024 characters)
518
        bitrate : Optional[:class:`int`]
519
            the bitrate (in bits) of the voice channel (voice only)
520
        user_limit : Optional[:class:`int`]
521
            the user limit of the voice channel (voice only)
522
        rate_limit_per_user : Optional[:class:`int`]
523
            amount of seconds a user has to wait before sending another message (0-21600)
524
            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...
525
        position : Optional[:class:`int`]
526
            sorting position of the channel
527
        permission_overwrites : Optional[List[:class:`~pincer.objects.guild.overwrite.Overwrite`]]
528
            the channel's permission overwrites
529
        parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
530
            id of the parent category for a channel
531
        nsfw : Optional[:class:`bool`]
532
            whether the channel is nsfw
533
        Returns
534
        -------
535
        :class:`~pincer.objects.guild.channel.Channel`
536
            The new channel object.
537
        """
538
        ...
539
540
    async def create_channel(self, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
541
        data = await self._http.post(f"guilds/{self.id}/channels", data=kwargs)
542
        return Channel.from_dict(construct_client_dict(self._client, data))
543
544
    async def modify_channel_positions(
545
        self, *channel: Dict[str, Optional[Union[int, bool, Snowflake]]]
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
546
    ):
547
        """|coro|
548
        Create a new channel object for the guild.
549
550
        Parameters
551
        ----------
552
553
        \\*channel : Dict[str, Optional[Union[int, bool, :class:`~pincer.utils.snowflake.Snowflake`]
554
            Keys:
555
                - id : :class:`~pincer.utils.snowflake.Snowflake`
556
                - position : Optional[:class:`int`]
557
                - lock_permissions : Optional[:class:`bool`]
558
                - parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
559
        """
560
        await self._http.patch(f"guilds/{self.id}/channels", data=channel)
561
562
    async def list_active_threads(self) -> Tuple[
563
        Generator[Union[PublicThread, PrivateThread]], Generator[GuildMember]]:
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
564
        """|coro|
565
        Returns all active threads in the guild, including public and private threads.
566
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
567
        Returns
568
        -------
569
        Generator[Union[:class:`~pincer.objects.guild.channel.PublicThread`, :class:`~pincer.objects.guild.channel.PrivateThread`]], Generator[:class:`~pincer.objects.guild.member.GuildMember`]]
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (194/100).

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

Loading history...
570
            The new member object.
571
        """
572
        data = await self._http.get(f"guilds/{self.id}/threads/active")
573
574
        threads = (
575
            Channel.from_dict(construct_client_dict(self._client, data))
576
            for channel in data["threads"]
577
        )
578
        members = (
579
            GuildMember.from_dict(construct_client_dict(self._client, data))
580
            for member in data["members"]
581
        )
582
583
        return threads, members
584
585
    async def list_guild_members(self, limit: int = 1, after: int = 0):
586
        """|coro|
587
        Returns a list of guild member objects that are members of the guild.
588
589
        Parameters
590
        ----------
591
        limit : int
592
            max number of members to return (1-1000) |default| :data:`1`
593
        after : int
594
            the highest user id in the previous page |default| :data:`0`
595
        """
596
597
        members = await self._http.get(
598
            f"guilds/{self.id}/members?{limit=!s}&{after=!s}"
599
        )
600
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
601
        return (GuildMember.from_dict(construct_client_dict(self._client, data)) for member in members)
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...
Comprehensibility Best Practice introduced by
Undefined variable 'data'
Loading history...
602
603
    async def search_guild_members(
604
        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...
605
        query: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
606
        limit: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
607
    ) -> List[GuildMember]:
608
        """|coro|
609
        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...
610
611
        Parameters
612
        ----------
613
        query : str
614
            Query string to match username(s) and nickname(s) against.
615
        limit : Optional[int]
616
            max number of members to return (1-1000) |default| :data:`1`
617
        Returns
618
        -------
619
        List[:class:`~pincer.objects.guild.member.GuildMember`]
620
            list of guild member objects
621
        """
622
623
        data = await self._http.get(
624
            f"guilds/{id}/members/search?{query=!s}"
625
            f"&{limit}" if limit else ""
626
        )
627
628
        return (GuildMember.from_dict(member) for member in data)
629
630
    @overload
631
    async def add_guild_member(
632
        self, *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
633
        user_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
634
        access_token: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
635
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
636
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
637
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
638
        deaf: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
639
    ) -> Optional[GuildMember]:
640
        """|coro|
641
        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...
642
643
        Parameters
644
        ----------
645
        user_id : str
646
            id of the user to be added
647
        access_token : str
648
            an oauth2 access token granted with the guilds.join to 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
649
            the bot's application for the user you want to add to the guild
650
        nick : Optional[str]
651
        	value to set users nickname to
652
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
653
        	array of role ids the member is assigned
654
        mute : Optional[bool]
655
        	whether the user is muted in voice channels
656
        deaf : Optional[bool]
657
        	whether the user is deafened in voice channels
658
659
        Returns
660
        -------
661
        :class:`~pincer.objects.guild.member.GuildMember`
662
            If the user is not in the guild
663
        None
664
            If the user is in the guild
665
        """
666
667
    async def add_guild_member(self, user_id, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
668
        data = await self._http.put(
669
            f"guilds/{self.id}/members/{user_id}", data=kwargs
670
        )
671
672
        return GuildMember.from_dict(data) if data else None
673
674
    async def modify_current_member(self, nick: str) -> GuildMember:
675
        """|coro|
676
        Modifies the current member in a guild.
677
678
        Parameters
679
        ----------
680
        nick : str
681
            value to set users nickname to
682
        Returns
683
        -------
684
        class:`~pincer.objects.guild.member.GuildMember
685
            current guild member
686
        """
687
        data = self._http.patch(f"guilds/{self.id}/members/@me", {"nick": nick})
688
        return GuildMember.from_dict(construct_client_dict(self._client, data))
689
690
    async def add_guild_member_role(self, user_id: int, role_id: int) -> None:
691
        """|coro|
692
        Adds a role to a guild member.
693
694
        Parameters
695
        ----------
696
        user_id : int
697
            id of the user to give a role to
698
        role_id : int
699
            id of a role
700
        """
701
        data = await self._http.put(
0 ignored issues
show
Unused Code introduced by
The variable data seems to be unused.
Loading history...
702
            f"guilds/{self.id}/{user_id}/roles/{role_id}", {}
703
        )
704
705
    async def remove_guild_member_role(
706
        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...
707
        user_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
708
        role_id: int
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
709
    ) -> None:
710
        """|coro|
711
        Removes a role from a guild member.
712
713
        Parameters
714
        ----------
715
        user_id : int
716
            id of the user to remove a role from
717
        role_id : int
718
            id of a role
719
        """
720
        await self._http.delete(
721
            f"guilds/{self.id}/{user_id}/roles/{role_id}"
722
        )
723
724
    async def remove_guild_member(self, user_id: int) -> None:
725
        """|coro|
726
        Remove a member from a guild.
727
728
        Parameters
729
        ----------
730
        user_id : int
731
            id of the user to remove from the guild
732
        """
733
        await self._http.delete(f"guilds/{self.id}/members/{user_id}")
734
735
    async def ban(
736
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
737
        member_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
738
        reason: str = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
739
        delete_message_days: int = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
740
    ):
741
        """
742
        Parameters
743
        ----------
744
        member_id : :class:`int`
745
            ID of the guild member to ban.
746
        reason : Optional[:class:`str`]
747
            Reason for the kick.
748
        delete_message_days : Optional[:class:`int`]
749
            Number of days to delete messages for (0-7)
750
        """
751
        headers = {}
752
753
        if reason is not None:
754
            headers["X-Audit-Log-Reason"] = reason
755
756
        data = {}
757
758
        if delete_message_days is not None:
759
            data["delete_message_days"] = delete_message_days
760
761
        await self._http.put(
762
            f"/guilds/{self.id}/bans/{member_id}",
763
            data=data,
764
            headers=headers
765
        )
766
767
    async def kick(self, member_id: int, reason: Optional[str] = None):
768
        """|coro|
769
        Kicks a guild member.
770
        Parameters
771
        ----------
772
        member_id : :class:`int`
773
            ID of the guild member to kick.
774
        reason : Optional[:class:`str`]
775
            Reason for the kick.
776
        """
777
778
        headers = {}
779
780
        if reason is not None:
781
            headers["X-Audit-Log-Reason"] = reason
782
783
        await self._http.delete(
784
            f"/guilds/{self.id}/members/{member_id}",
785
            header=headers
786
        )
787
788
    async def get_roles(self) -> AsyncGenerator[Role, None]:
789
        """|coro|
790
        Fetches all the roles in the guild.
791
792
        Yields
793
        -------
794
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
795
            An async generator of Role objects.
796
        """
797
        data = await self._http.get(f"guilds/{self.id}/roles")
798
        for role_data in data:
799
            yield Role.from_dict(construct_client_dict(self._client, role_data))
800
801
    @overload
802
    async def create_role(
803
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
804
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
805
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
806
        name: Optional[str] = "new role",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
807
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
808
        color: Optional[int] = 0,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
809
        hoist: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
810
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
811
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
812
        mentionable: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
813
    ) -> Role:
814
        """|coro|
815
        Creates a new role for the guild.
816
        Requires the ``MANAGE_ROLES`` permission.
817
818
        Parameters
819
        ----------
820
        reason : Optional[:class:`str`]
821
            Reason for creating the role. |default| :data:`None`
822
        name : Optional[:class:`str`]
823
            name of the role |default| :data:`"new role"`
824
        permissions : Optional[:class:`str`]
825
            bitwise value of the enabled/disabled
826
            permissions, set to @everyone permissions
827
            by default |default| :data:`None`
828
        color : Optional[:class:`int`]
829
            RGB color value |default| :data:`0`
830
        hoist : Optional[:class:`bool`]
831
            whether the role should be displayed
832
            separately in the sidebar |default| :data:`False`
833
        icon : Optional[:class:`str`]
834
            the role's icon image (if the guild has
835
            the ``ROLE_ICONS`` feature) |default| :data:`None`
836
        unicode_emoji : Optional[:class:`str`]
837
            the role's unicode emoji as a standard emoji (if the guild
838
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
839
        mentionable : Optional[:class:`bool`]
840
            whether the role should be mentionable |default| :data:`False`
841
842
        Returns
843
        -------
844
        :class:`~pincer.objects.guild.role.Role`
845
            The new role object.
846
        """
847
        ...
848
849
    async def create_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
850
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
851
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
852
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
853
    ) -> Role:
854
        return Role.from_dict(
855
            construct_client_dict(
856
                self._client,
857
                await self._http.post(
858
                    f"guilds/{self.id}/roles",
859
                    data=kwargs,
860
                    headers=remove_none({"X-Audit-Log-Reason": reason})
861
                ),
862
            )
863
        )
864
865
    async def edit_role_position(
866
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
867
        id: Snowflake,
0 ignored issues
show
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...
868
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
869
        position: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
870
    ) -> AsyncGenerator[Role, None]:
871
        """|coro|
872
        Edits the position of a role.
873
874
        Parameters
875
        ----------
876
        id : :class:`~pincer.utils.snowflake.Snowflake`
877
            The role ID
878
        reason : Optional[:class:`str`]
879
            Reason for editing the role position. |default| :data:`None`
880
        position : Optional[:class:`int`]
881
            Sorting position of the role |default| :data:`None`
882
883
        Yields
884
        -------
885
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
886
            An async generator of all of the guild's role objects.
887
        """
888
        data = await self._http.patch(
889
            f"guilds/{self.id}/roles",
890
            data={"id": id, "position": position},
891
            headers=remove_none({"X-Audit-Log-Reason": reason})
892
        )
893
        for role_data in data:
894
            yield Role.from_dict(construct_client_dict(self._client, role_data))
895
896
    @overload
897
    async def edit_role(
898
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
899
        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...
900
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
901
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
902
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
903
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
904
        color: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
905
        hoist: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
906
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
907
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
908
        mentionable: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
909
    ) -> Role:
910
        """|coro|
911
        Edits a role.
912
        Requires the ``MANAGE_ROLES`` permission.
913
914
        Parameters
915
        ----------
916
        id : :class:`~pincer.utils.snowflake.Snowflake`
917
            The role ID
918
        reason : Optional[:class:`str`]
919
            Reason for editing the role |default| :data:`None`
920
        name : Optional[:class:`str`]
921
            Name of the role |default| :data:`None`
922
        permissions : Optional[:class:`str`]
923
            Bitwise value of the enabled/disabled
924
            permissions |default| :data:`None`
925
        color : Optional[:class:`int`]
926
            RGB color value |default| :data:`None`
927
        hoist : Optional[:class:`bool`]
928
            Whether the role should be displayed
929
            separately in the sidebar |default| :data:`None`
930
        icon : Optional[:class:`str`]
931
            The role's icon image (if the guild has
932
            the ``ROLE_ICONS`` feature) |default| :data:`None`
933
        unicode_emoji : Optional[:class:`str`]
934
            The role's unicode emoji as a standard emoji (if the guild
935
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
936
        mentionable : Optional[:class:`bool`]
937
            Whether the role should be mentionable |default| :data:`None`
938
939
        Returns
940
        -------
941
        :class:`~pincer.objects.guild.role.Role`
942
            The edited role object.
943
        """
944
        ...
945
946
    async def edit_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
947
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
948
        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...
949
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
950
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
951
    ) -> Role:
952
        return Role.from_dict(
953
            construct_client_dict(
954
                self._client,
955
                await self._http.patch(
956
                    f"guilds/{self.id}/roles/{id}",
957
                    data=kwargs,
958
                    headers=remove_none({"X-Audit-Log-Reason": reason})
959
                ),
960
            )
961
        )
962
963
    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...
964
        """|coro|
965
        Deletes a role.
966
        Requires the `MANAGE_ROLES` permission.
967
968
        Parameters
969
        ----------
970
        id : :class:`~pincer.utils.snowflake.Snowflake`
971
            The role ID
972
        reason : Optional[:class:`str`]
973
            The reason for deleting the role |default| :data:`None`
974
        """
975
        await self._http.delete(
976
            f"guilds/{self.id}/roles/{id}",
977
            headers=remove_none({"X-Audit-Log-Reason": reason})
978
        )
979
980
    async def get_bans(self) -> AsyncGenerator[Ban, None]:
981
        """|coro|
982
        Fetches all the bans in the guild.
983
984
        Yields
985
        -------
986
        AsyncGenerator[:class:`~pincer.objects.guild.ban.Ban`, :data:`None`]
987
            An async generator of Ban objects.
988
        """
989
        data = await self._http.get(f"guilds/{self.id}/bans")
990
        for ban_data in data:
991
            yield Ban.from_dict(construct_client_dict(self._client, ban_data))
992
993
    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...
994
        """|coro|
995
        Fetches a ban from the guild.
996
997
        Parameters
998
        ----------
999
        id : :class:`~pincer.utils.snowflake.Snowflake`
1000
            The user ID
1001
1002
        Returns
1003
        -------
1004
        :class:`~pincer.objects.guild.ban.Ban`
1005
            The Ban object.
1006
        """
1007
        return Ban.from_dict(
1008
            construct_client_dict(
1009
                self._client,
1010
                await self._http.get(f"guilds/{self.id}/bans/{id}"),
1011
            )
1012
        )
1013
1014
    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...
1015
        """|coro|
1016
        Unbans a user from the guild.
1017
1018
        Parameters
1019
        ----------
1020
        id : :class:`~pincer.utils.snowflake.Snowflake`
1021
            The user ID
1022
        reason : Optional[:class:`str`]
1023
            The reason for unbanning the user |default| :data:`None`
1024
        """
1025
        await self._http.delete(
1026
            f"guilds/{self.id}/bans/{id}",
1027
            headers=remove_none({"X-Audit-Log-Reason": reason})
1028
        )
1029
1030
    @overload
1031
    async def edit(
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (20/15).
Loading history...
1032
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1033
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1034
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1035
        region: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1036
        verification_level: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1037
        default_message_notifications: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1038
        explicit_content_filter: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1039
        afk_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1040
        afk_timeout: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1041
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1042
        owner_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1043
        splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1044
        discovery_splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1045
        banner: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1046
        system_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1047
        system_channel_flags: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1048
        rules_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1049
        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...
1050
        preferred_locale: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1051
        features: Optional[List[GuildFeature]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1052
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1053
    ) -> Guild:
1054
        """|coro|
1055
        Modifies the guild
1056
1057
        Parameters
1058
        ----------
1059
        name : Optional[:class:`str`]
1060
            Guild name |default| :data:`None`
1061
        region : Optional[:class:`str`]
1062
            Guild voice region ID |default| :data:`None`
1063
        verification_level : Optional[:class:`int`]
1064
            Verification level |default| :data:`None`
1065
        default_message_notifications : Optional[:class:`int`]
1066
            Default message notification level |default| :data:`None`
1067
        explicit_content_filter : Optional[:class:`int`]
1068
            Explicit content filter level |default| :data:`None`
1069
        afk_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1070
            ID for AFK channel |default| :data:`None`
1071
        afk_timeout : Optional[:class:`int`]
1072
            AFK timeout in seconds |default| :data:`None`
1073
        icon : Optional[:class:`str`]
1074
            base64 1024x1024 png/jpeg/gif image for the guild icon
1075
            (can be animated gif when the server
1076
            has the `ANIMATED_ICON` feature) |default| :data:`None`
1077
        owner_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1078
            User ID to transfer guild ownership to (must be owner) |default| :data:`None`
1079
        splash : Optional[:class:`str`]
1080
            base64 16:9 png/jpeg image for the guild splash (when the
1081
            server has the `INVITE_SPLASH` feature) |default| :data:`None`
1082
        discovery_splash : Optional[:class:`str`]
1083
            base64 16:9 png/jpeg image for the guild discovery splash
1084
            (when the server has the `DISCOVERABLE` feature) |default| :data:`None`
1085
        banner : Optional[:class:`str`]
1086
            base64 16:9 png/jpeg image for the guild banner (when the
1087
            server has the `BANNER` feature) |default| :data:`None`
1088
        system_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1089
            The ID of the channel where guild notices such as welcome
1090
            messages and boost events are posted |default| :data:`None`
1091
        system_channel_flags : Optional[:class:`int`]
1092
            System channel flags |default| :data:`None`
1093
        rules_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1094
            The ID of the channel where Community guilds display rules
1095
            and/or guidelines |default| :data:`None`
1096
        public_updates_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1097
            The ID of the channel where admins and moderators of
1098
            Community guilds receive notices from Discord |default| :data:`None`
1099
        preferred_locale : Optional[:class:`str`]
1100
            The preferred locale of a Community guild used in server
1101
            discovery and notices from Discord; defaults to "en-US" |default| :data:`None`
1102
        features : Optional[List[:class:`GuildFeature`]]
1103
            Enabled guild features |default| :data:`None`
1104
        description : Optional[:class:`str`]
1105
            The description for the guild, if the guild is discoverable |default| :data:`None`
1106
1107
        Returns
1108
        -------
1109
        :class:`~pincer.objects.guild.Guild`
1110
            The modified guild object.
1111
        """
1112
        ...
1113
1114
    async def edit(self, **kwargs) -> Guild:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
1115
        g = await self._http.patch(f"guilds/{self.id}", data=kwargs)
1116
        return Guild.from_dict(construct_client_dict(self._client, g))
1117
1118
    async def preview(self) -> GuildPreview:
1119
        """|coro|
1120
        Previews the guild.
1121
1122
        Returns
1123
        -------
1124
        :class:`~pincer.objects.guild.guild.GuildPreview`
1125
            The guild preview object.
1126
        """
1127
        data = await self._http.get(f"guilds/{self.id}/preview")
1128
        return GuildPreview.from_dict(data)
1129
1130
    async def delete(self):
1131
        """|coro|
1132
        Deletes the guild. Returns `204 No Content` on success.
1133
        """
1134
        await self._http.delete(f"guilds/{self.id}")
1135
1136
    async def prune_count(
1137
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1138
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1139
        include_roles: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1140
    ) -> int:
1141
        """|coro|
1142
        Returns the number of members that
1143
        would be removed in a prune operation.
1144
        Requires the ``KICK_MEMBERS`` permission.
1145
1146
        Parameters
1147
        ----------
1148
        days : Optional[:class:`int`]
1149
            Number of days to count prune for (1-30) |default| :data:`7`
1150
        include_roles : Optional[:class:`str`]
1151
            Comma-delimited array of Snowflakes;
1152
            role(s) to include |default| :data:`None`
1153
1154
        Returns
1155
        -------
1156
        :class:`int`
1157
            The number of members that would be removed.
1158
        """
1159
        return await self._http.get(
1160
            f"guilds/{self.id}/prune?{days=}&{include_roles=!s}"
1161
        )["pruned"]
1162
1163
    async def prune(
1164
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1165
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1166
        compute_prune_days: Optional[bool] = True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1167
        include_roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1168
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1169
    ) -> int:
1170
        """|coro|
1171
        Prunes members from the guild. Requires the ``KICK_MEMBERS`` permission.
1172
1173
        Parameters
1174
1175
        Parameters
1176
        ----------
1177
        days : Optional[:class:`int`]
1178
            Number of days to prune (1-30) |default| :data:`7`
1179
        compute_prune_days : Optional[:class:`bool`]
1180
            Whether ``pruned`` is returned, discouraged for large guilds
1181
            |default| :data:`True`
1182
        include_roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1183
            role(s) to include |default| :data:`None`
1184
        reason : Optional[:class:`str`]
1185
            Reason for the prune |default| :data:`None`
1186
1187
        Returns
1188
        -------
1189
        :class:`int`
1190
            The number of members that were removed.
1191
        """
1192
        return await self._http.post(
1193
            f"guilds/{self.id}/prune",
1194
            data={
1195
                "days": days,
1196
                "compute_prune_days": compute_prune_days,
1197
                "include_roles": include_roles
1198
            },
1199
            headers=remove_none({"X-Audit-Log-Reason": reason})
1200
        )["pruned"]
1201
1202
    async def get_voice_regions(self) -> AsyncGenerator[VoiceRegion, None]:
1203
        """|coro|
1204
        Returns an async generator of voice regions.
1205
1206
        Yields
1207
        -------
1208
        AsyncGenerator[:class:`~pincer.objects.voice.VoiceRegion`, :data:`None`]
1209
            An async generator of voice regions.
1210
        """
1211
        data = await self._http.get(f"guilds/{self.id}/regions")
1212
        for voice_region_data in data:
1213
            yield VoiceRegion.from_dict(construct_client_dict(self._client, voice_region_data))
1214
1215
    async def get_invites(self) -> AsyncGenerator[Invite, None]:
1216
        """|coro|
1217
        Returns an async generator of invites for the guild.
1218
        Requires the ``MANAGE_GUILD`` permission.
1219
1220
        Yields
1221
        -------
1222
        AsyncGenerator[:class:`~pincer.objects.invite.Invite`, :data:`None`]
1223
            An async generator of invites.
1224
        """
1225
        data = await self._http.get(f"guilds/{self.id}/invites")
1226
        for invite_data in data:
1227
            yield Invite.from_dict(construct_client_dict(self._client, invite_data))
1228
1229
    async def get_integrations(self) -> AsyncGenerator[Integration, None]:
1230
        """|coro|
1231
        Returns an async generator of integrations for the guild.
1232
        Requires the ``MANAGE_GUILD`` permission.
1233
1234
        Yields
1235
        -------
1236
        AsyncGenerator[:class:`~pincer.objects.integration.Integration`, :data:`None`]
1237
            An async generator of integrations.
1238
        """
1239
        data = await self._http.get(f"guilds/{self.id}/integrations")
1240
        for integration_data in data:
1241
            yield Integration.from_dict(construct_client_dict(self._client, integration_data))
1242
1243
    async def delete_integration(
1244
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1245
        integration: Integration,
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
    ):
1248
        """|coro|
1249
        Deletes an integration.
1250
        Requires the ``MANAGE_GUILD`` permission.
1251
1252
        Parameters
1253
        ----------
1254
        integration : :class:`~pincer.objects.integration.Integration`
1255
            The integration to delete.
1256
        reason : Optional[:class:`str`]
1257
            Reason for the deletion |default| :data:`None`
1258
        """
1259
        await self._http.delete(
1260
            f"guilds/{self.id}/integrations/{integration.id}",
1261
            headers=remove_none({"X-Audit-Log-Reason": reason})
1262
        )
1263
1264
    async def get_widget_settings(self) -> GuildWidget:
1265
        """|coro|
1266
        Returns the guild widget settings.
1267
        Requires the ``MANAGE_GUILD`` permission.
1268
1269
        Returns
1270
        -------
1271
        :class:`~pincer.objects.guild.widget.GuildWidget`
1272
            The guild widget settings.
1273
        """
1274
        return GuildWidget.from_dict(
1275
            construct_client_dict(
1276
                self._client,
1277
                await self._http.get(f"guilds/{self.id}/widget")
1278
            )
1279
        )
1280
1281
    async def modify_widget(
1282
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1283
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1284
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1285
    ) -> GuildWidget:
1286
        """|coro|
1287
        Modifies the guild widget for the guild.
1288
        Requires the ``MANAGE_GUILD`` permission.
1289
1290
        Parameters
1291
        ----------
1292
        reason : Optional[:class:`str`]
1293
            Reason for the modification |default| :data:`None`
1294
        \\*\\*kwargs
1295
            The widget settings to modify
1296
1297
        Returns
1298
        -------
1299
        :class:`~pincer.objects.guild.widget.GuildWidget`
1300
            The updated GuildWidget object
1301
        """
1302
        data = await self._http.patch(
1303
            f"guilds/{self.id}/widget",
1304
            data=kwargs,
1305
            headers=remove_none({"X-Audit-Log-Reason": reason})
1306
        )
1307
        return GuildWidget.from_dict(construct_client_dict(self._client, data))
1308
1309
    async def get_widget(self) -> Dict[str, JSONSerializable]:
1310
        """|coro|
1311
        Returns the widget for the guild
1312
        """
1313
        return await self._http.get(f"guilds/{self.id}/widget.json")
1314
1315
    @property
1316
    async def vanity_url(self) -> Invite:
1317
        """|coro|
1318
        Returns the Vanity URL for the guild.
1319
        Requires the ``MANAGE_GUILD`` permission.
1320
        ``code`` will be null if a vanity URL has not been set.
1321
1322
        Returns
1323
        -------
1324
        :class:`~pincer.objects.guild.invite.Invite`
1325
            The vanity url for the guild.
1326
        """
1327
        data = await self._http.get(f"guilds/{self.id}/vanity-url")
1328
        return Invite.from_dict(construct_client_dict(self._client, data))
1329
1330
    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...
1331
        """|coro|
1332
        Returns a PNG image widget for the guild.
1333
        Requires no permissions or authentication.
1334
1335
        Widget Style Options
1336
        -------------------
1337
        * [``shield``](https://discord.com/api/guilds/81384788765712384/widget.png?style=shield)
1338
          shield style widget with Discord icon and guild members online count
1339
        * [``banner1``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner1)
1340
          large image with guild icon, name and online count.
1341
          "POWERED BY DISCORD" as the footer of the widget
1342
        * [``banner2``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner2)
1343
          smaller widget style with guild icon, name and online count.
1344
          Split on the right with Discord logo
1345
        * [``banner3``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner3)
1346
          large image with guild icon, name and online count.
1347
          In the footer, Discord logo on the
1348
          left and "Chat Now" on the right
1349
        * [``banner4``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner4)
1350
          large Discord logo at the top of the widget.
1351
          Guild icon, name and online count in the middle portion
1352
          of the widget and a "JOIN MY SERVER" button at the bottom
1353
1354
        Parameters
1355
        ----------
1356
        style : Optional[:class:`str`]
1357
            Style of the widget image returned |default| :data:`"shield"`
1358
1359
        Returns
1360
        -------
1361
        :class:`str`
1362
            A PNG image of the guild widget.
1363
        """
1364
        return await self._http.get(f"guilds/{self.id}/widget.png?{style=!s}")
1365
1366
    async def get_welcome_screen(self) -> WelcomeScreen:
1367
        """Returns the welcome screen for the guild.
1368
1369
        Returns
1370
        -------
1371
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1372
            The welcome screen for the guild.
1373
        """
1374
        data = await self._http.get(f"guilds/{self.id}/welcome-screen")
1375
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1376
1377
    async def modify_welcome_screen(
1378
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1379
        enabled: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1380
        welcome_channels: Optional[List[WelcomeScreenChannel]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1381
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1382
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1383
    ) -> WelcomeScreen:
1384
        """|coro|
1385
        Modifies the guild's Welcome Screen.
1386
        Requires the ``MANAGE_GUILD`` permission.
1387
1388
        Parameters
1389
        ----------
1390
        enabled : Optional[:class:`bool`]
1391
            Whether the welcome screen is enabled |default| :data:`None`
1392
        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...
1393
            Channels linked in the welcome screen and
1394
            their display options |default| :data:`None`
1395
        description : Optional[:class:`str`]
1396
            The server description to show
1397
            in the welcome screen |default| :data:`None`
1398
        reason : Optional[:class:`str`]
1399
            Reason for the modification |default| :data:`None`
1400
1401
        Returns
1402
        -------
1403
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1404
            The updated WelcomeScreen object
1405
        """
1406
        data = await self._http.patch(
1407
            f"guilds/{self.id}/welcome-screen",
1408
            data={
1409
                "enabled": enabled,
1410
                "welcome_channels": welcome_channels,
1411
                "description": description
1412
            },
1413
            headers=remove_none({"X-Audit-Log-Reason": reason})
1414
        )
1415
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1416
1417
    async def modify_current_user_voice_state(
1418
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1419
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1420
        suppress: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1421
        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...
1422
    ):
1423
        """|coro|
1424
        Updates the current 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
        * current user must already have joined ``channel_id``
1429
        * You must have the ``MUTE_MEMBERS`` permission to
1430
          unsuppress yourself. You can always suppress yourself.
1431
        * You must have the ``REQUEST_TO_SPEAK`` permission to request
1432
          to speak. You can always clear your own request to speak.
1433
        * You are able to set ``request_to_speak_timestamp`` to any
1434
          present or future time.
1435
1436
        Parameters
1437
        ----------
1438
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1439
            The ID of the channel the user is currently in
1440
        suppress : Optional[:class:`bool`]
1441
            Toggles the user's suppress state |default| :data:`None`
1442
        request_to_speak_timestamp : Optional[:class:`~pincer.utils.timestamp.Timestamp`]
1443
            Sets the user's request to speak
1444
        """
1445
        await self._http.patch(
1446
            f"guilds/{self.id}/voice-states/@me",
1447
            data={
1448
                "channel_id": channel_id,
1449
                "suppress": suppress,
1450
                "request_to_speak_timestamp": request_to_speak_timestamp
1451
            }
1452
        )
1453
1454
    async def modify_user_voice_state(
1455
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1456
        user: User,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1457
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1458
        suppress: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1459
    ):
1460
        """|coro|
1461
        Updates another user's voice state.
1462
1463
        There are currently several caveats for this endpoint:
1464
        * ``channel_id`` must currently point to a stage channel
1465
        * User must already have joined ``channel_id``
1466
        * You must have the ``MUTE_MEMBERS`` permission.
1467
          (Since suppression is the only thing that is available currently.)
1468
        * When unsuppressed, non-bot users will have their
1469
          ``request_to_speak_timestamp`` set to the current time.
1470
          Bot users will not.
1471
        * When suppressed, the user will have their
1472
          ``request_to_speak_timestamp`` removed.
1473
1474
        Parameters
1475
        ----------
1476
        user : :class:`~pincer.objects.guild.member.Member`
1477
            The user to update
1478
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1479
            The ID of the channel the user is currently in
1480
        suppress : Optional[:class:`bool`]
1481
            Toggles the user's suppress state |default| :data:`None`
1482
        """
1483
        await self._http.patch(
1484
            f"guilds/{self.id}/voice-states/{user.id}",
1485
            data={
1486
                "channel_id": channel_id,
1487
                "suppress": suppress
1488
            }
1489
        )
1490
1491
    async def get_audit_log(self) -> AuditLog:
1492
        """|coro|
1493
        Returns an audit log object for the guild.
1494
        Requires the ``VIEW_AUDIT_LOG`` permission.
1495
1496
        Returns
1497
        -------
1498
        :class:`~pincer.objects.guild.audit_log.AuditLog`
1499
            The audit log object for the guild.
1500
        """
1501
        return AuditLog.from_dict(
1502
            construct_client_dict(
1503
                self._client,
1504
                await self._http.get(f"guilds/{self.id}/audit-logs")
1505
            )
1506
        )
1507
1508
    async def get_emojis(self) -> AsyncGenerator[Emoji, None]:
1509
        """|coro|
1510
        Returns an async generator of the emojis in the guild.
1511
1512
        Yields
1513
        ------
1514
        :class:`~pincer.objects.guild.emoji.Emoji`
1515
            The emoji object.
1516
        """
1517
        data = await self._http.get(f"guilds/{self.id}/emojis")
1518
        for emoji_data in data:
1519
            yield Emoji.from_dict(
1520
                construct_client_dict(self._client, emoji_data)
1521
            )
1522
1523
    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...
1524
        """|coro|
1525
        Returns an emoji object for the given ID.
1526
1527
        Parameters
1528
        ----------
1529
        id : :class:`~pincer.utils.snowflake.Snowflake`
1530
            The ID of the emoji
1531
1532
        Returns
1533
        -------
1534
        :class:`~pincer.objects.guild.emoji.Emoji`
1535
            The emoji object.
1536
        """
1537
        return Emoji.from_dict(
1538
            construct_client_dict(
1539
                self._client,
1540
                await self._http.get(f"guilds/{self.id}/emojis/{id}")
1541
            )
1542
        )
1543
1544
    async def create_emoji(
0 ignored issues
show
Bug Best Practice introduced by
The default value [] might cause unintended side-effects.

Objects as default values are only created once in Python and not on each invocation of the function. If the default object is modified, this modification is carried over to the next invocation of the method.

# Bad:
# If array_param is modified inside the function, the next invocation will
# receive the modified object.
def some_function(array_param=[]):
    # ...

# Better: Create an array on each invocation
def some_function(array_param=None):
    array_param = array_param or []
    # ...
Loading history...
1545
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1546
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1547
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1548
        image: File,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1549
        roles: List[Snowflake] = [],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1550
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1551
    ) -> Emoji:
1552
        """|coro|
1553
        Creates a new emoji for the guild.
1554
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1555
1556
        Emojis and animated emojis have a maximum file size of 256kb.
1557
        Attempting to upload an emoji larger than this limit will fail.
1558
1559
        Parameters
1560
        ----------
1561
        name : :class:`str`
1562
            Name of the emoji
1563
        image : :class:`~pincer.objects.message.file.File`
1564
            The File for the 128x128 emoji image data
1565
        roles : List[:class:`~pincer.utils.snowflake.Snowflake`]
1566
            Roles allowed to use this emoji |default| :data:`[]`
1567
        reason : Optional[:class:`str`]
1568
            The reason for creating the emoji |default| :data:`None`
1569
1570
        Returns
1571
        -------
1572
        :class:`~pincer.objects.guild.emoji.Emoji`
1573
            The newly created emoji object.
1574
        """
1575
        data = await self._http.post(
1576
            f"guilds/{self.id}/emojis",
1577
            data={
1578
                "name": name,
1579
                "image": image.uri,
1580
                "roles": roles
1581
            },
1582
            headers=remove_none({"X-Audit-Log-Reason": reason})
1583
        )
1584
        return Emoji.from_dict(
1585
            construct_client_dict(self._client, data)
1586
        )
1587
1588
    async def edit_emoji(
1589
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1590
        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...
1591
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1592
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1593
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1594
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1595
    ) -> Emoji:
1596
        """|coro|
1597
        Modifies the given emoji.
1598
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1599
1600
        Parameters
1601
        ----------
1602
        id : :class:`~pincer.utils.snowflake.Snowflake`
1603
            The ID of the emoji
1604
        name : Optional[:class:`str`]
1605
            Name of the emoji |default| :data:`None`
1606
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1607
            Roles allowed to use this emoji |default| :data:`None`
1608
        reason : Optional[:class:`str`]
1609
            The reason for editing the emoji |default| :data:`None`
1610
1611
        Returns
1612
        -------
1613
        :class:`~pincer.objects.guild.emoji.Emoji`
1614
            The modified emoji object.
1615
        """
1616
        data = await self._http.patch(
1617
            f"guilds/{self.id}/emojis/{id}",
1618
            data={
1619
                "name": name,
1620
                "roles": roles
1621
            },
1622
            headers=remove_none({"X-Audit-Log-Reason": reason})
1623
        )
1624
        return Emoji.from_dict(
1625
            construct_client_dict(self._client, data)
1626
        )
1627
1628
    async def delete_emoji(
1629
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1630
        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...
1631
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1632
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1633
    ):
1634
        """|coro|
1635
        Deletes the given emoji.
1636
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1637
1638
        Parameters
1639
        ----------
1640
        id : :class:`~pincer.utils.snowflake.Snowflake`
1641
            The ID of the emoji
1642
        reason : Optional[:class:`str`]
1643
            The reason for deleting the emoji |default| :data:`None`
1644
        """
1645
        await self._http.delete(
1646
            f"guilds/{self.id}/emojis/{id}",
1647
            headers=remove_none({"X-Audit-Log-Reason": reason})
1648
        )
1649
1650
    async def get_templates(self) -> AsyncGenerator[GuildTemplate, None]:
1651
        """|coro|
1652
        Returns an async generator of the guild templates.
1653
1654
        Yields
1655
        -------
1656
        AsyncGenerator[:class:`~pincer.objects.guild.template.GuildTemplate`, :data:`None`]
1657
            The guild template object.
1658
        """
1659
        data = await self._http.get(f"guilds/{self.id}/templates")
1660
        for template_data in data:
1661
            yield GuildTemplate.from_dict(
1662
                construct_client_dict(self._client, template_data)
1663
            )
1664
1665
    async def create_template(
1666
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1667
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1668
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1669
    ) -> GuildTemplate:
1670
        """|coro|
1671
        Creates a new template for the guild.
1672
        Requires the ``MANAGE_GUILD`` permission.
1673
1674
        Parameters
1675
        ----------
1676
        name : :class:`str`
1677
            Name of the template (1-100 characters)
1678
        description : Optional[:class:`str`]
1679
            Description of the template
1680
            (0-120 characters) |default| :data:`None`
1681
        Returns
1682
        -------
1683
        :class:`~pincer.objects.guild.template.GuildTemplate`
1684
            The newly created template object.
1685
        """
1686
        data = await self._http.post(
1687
            f"guilds/{self.id}/templates",
1688
            data={
1689
                "name": name,
1690
                "description": description
1691
            }
1692
        )
1693
        return GuildTemplate.from_dict(
1694
            construct_client_dict(self._client, data)
1695
        )
1696
1697
    async def sync_template(
1698
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1699
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1700
    ) -> GuildTemplate:
1701
        """|coro|
1702
        Syncs the given template.
1703
        Requires the ``MANAGE_GUILD`` permission.
1704
1705
        Parameters
1706
        ----------
1707
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1708
            The template to sync
1709
1710
        Returns
1711
        -------
1712
        :class:`~pincer.objects.guild.template.GuildTemplate`
1713
            The synced template object.
1714
        """
1715
        data = await self._http.put(
1716
            f"guilds/{self.id}/templates/{template.code}"
1717
        )
1718
        return GuildTemplate.from_dict(
1719
            construct_client_dict(self._client, data)
1720
        )
1721
1722
    async def edit_template(
1723
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1724
        template: GuildTemplate,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1725
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1726
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1727
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1728
    ) -> GuildTemplate:
1729
        """|coro|
1730
        Modifies the template's metadata.
1731
        Requires the ``MANAGE_GUILD`` permission.
1732
1733
        Parameters
1734
        ----------
1735
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1736
            The template to edit
1737
        name : Optional[:class:`str`]
1738
            Name of the template (1-100 characters)
1739
            |default| :data:`None`
1740
        description : Optional[:class:`str`]
1741
            Description of the template (0-120 characters)
1742
            |default| :data:`None`
1743
1744
        Returns
1745
        -------
1746
        :class:`~pincer.objects.guild.template.GuildTemplate`
1747
            The edited template object.
1748
        """
1749
        data = await self._http.patch(
1750
            f"guilds/{self.id}/templates/{template.code}",
1751
            data={
1752
                "name": name,
1753
                "description": description
1754
            }
1755
        )
1756
        return GuildTemplate.from_dict(
1757
            construct_client_dict(self._client, data)
1758
        )
1759
1760
    async def delete_template(
1761
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1762
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1763
    ) -> GuildTemplate:
1764
        """|coro|
1765
        Deletes the given template.
1766
        Requires the ``MANAGE_GUILD`` permission.
1767
1768
        Parameters
1769
        ----------
1770
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1771
            The template to delete
1772
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1773
        Returns
1774
        -------
1775
        :class:`~pincer.objects.guild.template.GuildTemplate`
1776
            The deleted template object.
1777
        """
1778
        data = await self._http.delete(
1779
            f"guilds/{self.id}/templates/{template.code}"
1780
        )
1781
        return GuildTemplate.from_dict(
1782
            construct_client_dict(self._client, data)
1783
        )
1784
1785
    async def get_webhooks(self) -> AsyncGenerator[Webhook, None]:
1786
        """|coro|
1787
        Returns an async generator of the guild webhooks.
1788
1789
        Yields
1790
        -------
1791
        AsyncGenerator[:class:`~pincer.objects.guild.webhook.Webhook`, None]
1792
            The guild webhook object.
1793
        """
1794
        data = await self._http.get(f"guilds/{self.id}/webhooks")
1795
        for webhook_data in data:
1796
            yield Webhook.from_dict(
1797
                construct_client_dict(self._client, webhook_data)
1798
            )
1799
1800
    @classmethod
1801
    def from_dict(cls, data) -> Guild:
1802
        """
1803
        Parameters
1804
        ----------
1805
        data : :class:`Dict`
1806
            Guild data received from the discord API.
1807
        Returns
1808
        -------
1809
        :class:`~pincer.objects.guild.guild.Guild`
1810
            The new guild object.
1811
        Raises
1812
        :class:`~pincer.exceptions.UnavailableGuildError`
1813
            The guild is unavailable due to a discord outage.
1814
        """
1815
        if data.get("unavailable", False):
1816
            raise UnavailableGuildError(
1817
                f"Guild \"{data['id']}\" is unavailable due to a discord"
1818
                " outage."
1819
            )
1820
1821
        return super().from_dict(data)
1822
1823
1824
@dataclass(repr=False)
1825
class UnavailableGuild(APIObject):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
1826
    id: Snowflake
1827
    unavailable: bool = True
1828