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

Guild.edit_role_position()   A

Complexity

Conditions 2

Size

Total Lines 30
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

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

Loading history...
520
        position : Optional[:class:`int`]
521
            sorting position of the channel
522
        permission_overwrites : Optional[List[:class:`~pincer.objects.guild.overwrite.Overwrite`]]
523
            the channel's permission overwrites
524
        parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
525
            id of the parent category for a channel
526
        nsfw : Optional[:class:`bool`]
527
            whether the channel is nsfw
528
        Returns
529
        -------
530
        :class:`~pincer.objects.guild.channel.Channel`
531
            The new channel object.
532
        """
533
        ...
534
535
    async def create_channel(self, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
536
        data = await self._http.post(f"guilds/{self.id}/channels", data=kwargs)
537
        return Channel.from_dict(construct_client_dict(self._client, data))
538
539
    async def modify_channel_positions(
540
        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...
541
    ):
542
        """|coro|
543
        Create a new channel object for the guild.
544
545
        Parameters
546
        ----------
547
548
        \\*channel : Dict[str, Optional[Union[int, bool, :class:`~pincer.utils.snowflake.Snowflake`]
549
            Keys:
550
                - id : :class:`~pincer.utils.snowflake.Snowflake`
551
                - position : Optional[:class:`int`]
552
                - lock_permissions : Optional[:class:`bool`]
553
                - parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
554
        """
555
        await self._http.patch(f"guilds/{self.id}/channels", data=channel)
556
557
    async def list_active_threads(self) -> Tuple[
558
        Generator[Union[PublicThread, PrivateThread]], Generator[GuildMember]]:
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
559
        """|coro|
560
        Returns all active threads in the guild, including public and private threads.
561
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
562
        Returns
563
        -------
564
        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...
565
            The new member object.
566
        """
567
        data = await self._http.get(f"guilds/{self.id}/threads/active")
568
569
        threads = (
570
            Channel.from_dict(construct_client_dict(self._client, data))
571
            for channel in data["threads"]
572
        )
573
        members = (
574
            GuildMember.from_dict(construct_client_dict(self._client, data))
575
            for member in data["members"]
576
        )
577
578
        return threads, members
579
580
    async def list_guild_members(self, limit: int = 1, after: int = 0):
581
        """|coro|
582
        Returns a list of guild member objects that are members of the guild.
583
584
        Parameters
585
        ----------
586
        limit : int
587
            max number of members to return (1-1000) |default| :data:`1`
588
        after : int
589
            the highest user id in the previous page |default| :data:`0`
590
        """
591
592
        members = await self._http.get(
593
            f"guilds/{self.id}/members?{limit=!s}&{after=!s}"
594
        )
595
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
596
        return (GuildMember.from_dict(construct_client_dict(self._client, data)) for member in members)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'data'
Loading history...
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...
597
598
    async def search_guild_members(
599
        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...
600
        query: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
601
        limit: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
602
    ) -> List[GuildMember]:
603
        """|coro|
604
        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...
605
606
        Parameters
607
        ----------
608
        query : str
609
            Query string to match username(s) and nickname(s) against.
610
        limit : Optional[int]
611
            max number of members to return (1-1000) |default| :data:`1`
612
        Returns
613
        -------
614
        List[:class:`~pincer.objects.guild.member.GuildMember`]
615
            list of guild member objects
616
        """
617
618
        data = await self._http.get(
619
            f"guilds/{id}/members/search?{query=!s}"
620
            f"&{limit}" if limit else ""
621
        )
622
623
        return (GuildMember.from_dict(member) for member in data)
624
625
    @overload
626
    async def add_guild_member(
627
        self, *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
628
        user_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
629
        access_token: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
630
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
631
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
632
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
633
        deaf: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
634
    ) -> Optional[GuildMember]:
635
        """|coro|
636
        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...
637
638
        Parameters
639
        ----------
640
        user_id : str
641
            id of the user to be added
642
        access_token : str
643
            an oauth2 access token granted with the guilds.join to 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
644
            the bot's application for the user you want to add to the guild
645
        nick : Optional[str]
646
        	value to set users nickname to
647
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
648
        	array of role ids the member is assigned
649
        mute : Optional[bool]
650
        	whether the user is muted in voice channels
651
        deaf : Optional[bool]
652
        	whether the user is deafened in voice channels
653
654
        Returns
655
        -------
656
        :class:`~pincer.objects.guild.member.GuildMember`
657
            If the user is not in the guild
658
        None
659
            If the user is in the guild
660
        """
661
662
    async def add_guild_member(self, user_id, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
663
        data = await self._http.put(
664
            f"guilds/{self.id}/members/{user_id}", data=kwargs
665
        )
666
667
        return GuildMember.from_dict(data) if data else None
668
669
    async def modify_current_member(self, nick: str) -> GuildMember:
670
        """|coro|
671
        Modifies the current member in a guild.
672
673
        Parameters
674
        ----------
675
        nick : str
676
            value to set users nickname to
677
        Returns
678
        -------
679
        class:`~pincer.objects.guild.member.GuildMember
680
            current guild member
681
        """
682
        data = self._http.patch(f"guilds/{self.id}/members/@me", {"nick": nick})
683
        return GuildMember.from_dict(construct_client_dict(self._client, data))
684
685
    async def add_guild_member_role(self, user_id: int, role_id: int) -> None:
686
        """|coro|
687
        Adds a role to a guild member.
688
689
        Parameters
690
        ----------
691
        user_id : int
692
            id of the user to give a role to
693
        role_id : int
694
            id of a role
695
        """
696
        data = await self._http.put(
0 ignored issues
show
Unused Code introduced by
The variable data seems to be unused.
Loading history...
697
            f"guilds/{self.id}/{user_id}/roles/{role_id}", {}
698
        )
699
700
    async def remove_guild_member_role(
701
        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...
702
        user_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
703
        role_id: int
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
704
    ) -> None:
705
        """|coro|
706
        Removes a role from a guild member.
707
708
        Parameters
709
        ----------
710
        user_id : int
711
            id of the user to remove a role from
712
        role_id : int
713
            id of a role
714
        """
715
        await self._http.delete(
716
            f"guilds/{self.id}/{user_id}/roles/{role_id}"
717
        )
718
719
    async def remove_guild_member(self, user_id: int) -> None:
720
        """|coro|
721
        Remove a member from a guild.
722
723
        Parameters
724
        ----------
725
        user_id : int
726
            id of the user to remove from the guild
727
        """
728
        await self._http.delete(f"guilds/{self.id}/members/{user_id}")
729
730
    async def ban(
731
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
732
        member_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
733
        reason: str = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
734
        delete_message_days: int = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
735
    ):
736
        """
737
        Parameters
738
        ----------
739
        member_id : :class:`int`
740
            ID of the guild member to ban.
741
        reason : Optional[:class:`str`]
742
            Reason for the kick.
743
        delete_message_days : Optional[:class:`int`]
744
            Number of days to delete messages for (0-7)
745
        """
746
        headers = {}
747
748
        if reason is not None:
749
            headers["X-Audit-Log-Reason"] = reason
750
751
        data = {}
752
753
        if delete_message_days is not None:
754
            data["delete_message_days"] = delete_message_days
755
756
        await self._http.put(
757
            f"/guilds/{self.id}/bans/{member_id}",
758
            data=data,
759
            headers=headers
760
        )
761
762
    async def kick(self, member_id: int, reason: Optional[str] = None):
763
        """|coro|
764
        Kicks a guild member.
765
        Parameters
766
        ----------
767
        member_id : :class:`int`
768
            ID of the guild member to kick.
769
        reason : Optional[:class:`str`]
770
            Reason for the kick.
771
        """
772
773
        headers = {}
774
775
        if reason is not None:
776
            headers["X-Audit-Log-Reason"] = reason
777
778
        await self._http.delete(
779
            f"/guilds/{self.id}/members/{member_id}",
780
            header=headers
781
        )
782
783
    async def get_roles(self) -> AsyncGenerator[Role, None]:
784
        """|coro|
785
        Fetches all the roles in the guild.
786
787
        Yields
788
        -------
789
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
790
            An async generator of Role objects.
791
        """
792
        data = await self._http.get(f"guilds/{self.id}/roles")
793
        for role_data in data:
794
            yield Role.from_dict(construct_client_dict(self._client, role_data))
795
796
    @overload
797
    async def create_role(
798
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
799
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
800
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
801
        name: Optional[str] = "new role",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
802
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
803
        color: Optional[int] = 0,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
804
        hoist: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
805
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
806
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
807
        mentionable: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
808
    ) -> Role:
809
        """|coro|
810
        Creates a new role for the guild.
811
        Requires the ``MANAGE_ROLES`` permission.
812
813
        Parameters
814
        ----------
815
        reason : Optional[:class:`str`]
816
            Reason for creating the role. |default| :data:`None`
817
        name : Optional[:class:`str`]
818
            name of the role |default| :data:`"new role"`
819
        permissions : Optional[:class:`str`]
820
            bitwise value of the enabled/disabled
821
            permissions, set to @everyone permissions
822
            by default |default| :data:`None`
823
        color : Optional[:class:`int`]
824
            RGB color value |default| :data:`0`
825
        hoist : Optional[:class:`bool`]
826
            whether the role should be displayed
827
            separately in the sidebar |default| :data:`False`
828
        icon : Optional[:class:`str`]
829
            the role's icon image (if the guild has
830
            the ``ROLE_ICONS`` feature) |default| :data:`None`
831
        unicode_emoji : Optional[:class:`str`]
832
            the role's unicode emoji as a standard emoji (if the guild
833
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
834
        mentionable : Optional[:class:`bool`]
835
            whether the role should be mentionable |default| :data:`False`
836
837
        Returns
838
        -------
839
        :class:`~pincer.objects.guild.role.Role`
840
            The new role object.
841
        """
842
        ...
843
844
    async def create_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
845
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
846
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
847
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
848
    ) -> Role:
849
        return Role.from_dict(
850
            construct_client_dict(
851
                self._client,
852
                await self._http.post(
853
                    f"guilds/{self.id}/roles",
854
                    data=kwargs,
855
                    headers=remove_none({"X-Audit-Log-Reason": reason})
856
                ),
857
            )
858
        )
859
860
    async def edit_role_position(
861
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
862
        id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
863
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
864
        position: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
865
    ) -> AsyncGenerator[Role, None]:
866
        """|coro|
867
        Edits the position of a role.
868
869
        Parameters
870
        ----------
871
        id : :class:`~pincer.utils.snowflake.Snowflake`
872
            The role ID
873
        reason : Optional[:class:`str`]
874
            Reason for editing the role position. |default| :data:`None`
875
        position : Optional[:class:`int`]
876
            Sorting position of the role |default| :data:`None`
877
878
        Yields
879
        -------
880
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
881
            An async generator of all of the guild's role objects.
882
        """
883
        data = await self._http.patch(
884
            f"guilds/{self.id}/roles",
885
            data={"id": id, "position": position},
886
            headers=remove_none({"X-Audit-Log-Reason": reason})
887
        )
888
        for role_data in data:
889
            yield Role.from_dict(construct_client_dict(self._client, role_data))
890
891
    @overload
892
    async def edit_role(
893
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
894
        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...
895
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
896
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
897
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
898
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
899
        color: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
900
        hoist: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
901
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
902
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
903
        mentionable: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
904
    ) -> Role:
905
        """|coro|
906
        Edits a role.
907
        Requires the ``MANAGE_ROLES`` permission.
908
909
        Parameters
910
        ----------
911
        id : :class:`~pincer.utils.snowflake.Snowflake`
912
            The role ID
913
        reason : Optional[:class:`str`]
914
            Reason for editing the role |default| :data:`None`
915
        name : Optional[:class:`str`]
916
            Name of the role |default| :data:`None`
917
        permissions : Optional[:class:`str`]
918
            Bitwise value of the enabled/disabled
919
            permissions |default| :data:`None`
920
        color : Optional[:class:`int`]
921
            RGB color value |default| :data:`None`
922
        hoist : Optional[:class:`bool`]
923
            Whether the role should be displayed
924
            separately in the sidebar |default| :data:`None`
925
        icon : Optional[:class:`str`]
926
            The role's icon image (if the guild has
927
            the ``ROLE_ICONS`` feature) |default| :data:`None`
928
        unicode_emoji : Optional[:class:`str`]
929
            The role's unicode emoji as a standard emoji (if the guild
930
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
931
        mentionable : Optional[:class:`bool`]
932
            Whether the role should be mentionable |default| :data:`None`
933
934
        Returns
935
        -------
936
        :class:`~pincer.objects.guild.role.Role`
937
            The edited role object.
938
        """
939
        ...
940
941
    async def edit_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
942
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
943
        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...
944
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
945
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
946
    ) -> Role:
947
        return Role.from_dict(
948
            construct_client_dict(
949
                self._client,
950
                await self._http.patch(
951
                    f"guilds/{self.id}/roles/{id}",
952
                    data=kwargs,
953
                    headers=remove_none({"X-Audit-Log-Reason": reason})
954
                ),
955
            )
956
        )
957
958
    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...
959
        """|coro|
960
        Deletes a role.
961
        Requires the `MANAGE_ROLES` permission.
962
963
        Parameters
964
        ----------
965
        id : :class:`~pincer.utils.snowflake.Snowflake`
966
            The role ID
967
        reason : Optional[:class:`str`]
968
            The reason for deleting the role |default| :data:`None`
969
        """
970
        await self._http.delete(
971
            f"guilds/{self.id}/roles/{id}",
972
            headers=remove_none({"X-Audit-Log-Reason": reason})
973
        )
974
975
    async def get_bans(self) -> AsyncGenerator[Ban, None]:
976
        """|coro|
977
        Fetches all the bans in the guild.
978
979
        Yields
980
        -------
981
        AsyncGenerator[:class:`~pincer.objects.guild.ban.Ban`, :data:`None`]
982
            An async generator of Ban objects.
983
        """
984
        data = await self._http.get(f"guilds/{self.id}/bans")
985
        for ban_data in data:
986
            yield Ban.from_dict(construct_client_dict(self._client, ban_data))
987
988
    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...
989
        """|coro|
990
        Fetches a ban from the guild.
991
992
        Parameters
993
        ----------
994
        id : :class:`~pincer.utils.snowflake.Snowflake`
995
            The user ID
996
997
        Returns
998
        -------
999
        :class:`~pincer.objects.guild.ban.Ban`
1000
            The Ban object.
1001
        """
1002
        return Ban.from_dict(
1003
            construct_client_dict(
1004
                self._client,
1005
                await self._http.get(f"guilds/{self.id}/bans/{id}"),
1006
            )
1007
        )
1008
1009
    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...
1010
        """|coro|
1011
        Unbans a user from the guild.
1012
1013
        Parameters
1014
        ----------
1015
        id : :class:`~pincer.utils.snowflake.Snowflake`
1016
            The user ID
1017
        reason : Optional[:class:`str`]
1018
            The reason for unbanning the user |default| :data:`None`
1019
        """
1020
        await self._http.delete(
1021
            f"guilds/{self.id}/bans/{id}",
1022
            headers=remove_none({"X-Audit-Log-Reason": reason})
1023
        )
1024
1025
    @overload
1026
    async def edit(
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (20/15).
Loading history...
1027
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1028
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1029
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1030
        region: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1031
        verification_level: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1032
        default_message_notifications: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1033
        explicit_content_filter: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1034
        afk_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1035
        afk_timeout: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1036
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1037
        owner_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1038
        splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1039
        discovery_splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1040
        banner: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1041
        system_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1042
        system_channel_flags: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1043
        rules_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1044
        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...
1045
        preferred_locale: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1046
        features: Optional[List[GuildFeature]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1047
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1048
    ) -> Guild:
1049
        """|coro|
1050
        Modifies the guild
1051
1052
        Parameters
1053
        ----------
1054
        name : Optional[:class:`str`]
1055
            Guild name |default| :data:`None`
1056
        region : Optional[:class:`str`]
1057
            Guild voice region ID |default| :data:`None`
1058
        verification_level : Optional[:class:`int`]
1059
            Verification level |default| :data:`None`
1060
        default_message_notifications : Optional[:class:`int`]
1061
            Default message notification level |default| :data:`None`
1062
        explicit_content_filter : Optional[:class:`int`]
1063
            Explicit content filter level |default| :data:`None`
1064
        afk_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1065
            ID for AFK channel |default| :data:`None`
1066
        afk_timeout : Optional[:class:`int`]
1067
            AFK timeout in seconds |default| :data:`None`
1068
        icon : Optional[:class:`str`]
1069
            base64 1024x1024 png/jpeg/gif image for the guild icon
1070
            (can be animated gif when the server
1071
            has the `ANIMATED_ICON` feature) |default| :data:`None`
1072
        owner_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1073
            User ID to transfer guild ownership to (must be owner) |default| :data:`None`
1074
        splash : Optional[:class:`str`]
1075
            base64 16:9 png/jpeg image for the guild splash (when the
1076
            server has the `INVITE_SPLASH` feature) |default| :data:`None`
1077
        discovery_splash : Optional[:class:`str`]
1078
            base64 16:9 png/jpeg image for the guild discovery splash
1079
            (when the server has the `DISCOVERABLE` feature) |default| :data:`None`
1080
        banner : Optional[:class:`str`]
1081
            base64 16:9 png/jpeg image for the guild banner (when the
1082
            server has the `BANNER` feature) |default| :data:`None`
1083
        system_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1084
            The ID of the channel where guild notices such as welcome
1085
            messages and boost events are posted |default| :data:`None`
1086
        system_channel_flags : Optional[:class:`int`]
1087
            System channel flags |default| :data:`None`
1088
        rules_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1089
            The ID of the channel where Community guilds display rules
1090
            and/or guidelines |default| :data:`None`
1091
        public_updates_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1092
            The ID of the channel where admins and moderators of
1093
            Community guilds receive notices from Discord |default| :data:`None`
1094
        preferred_locale : Optional[:class:`str`]
1095
            The preferred locale of a Community guild used in server
1096
            discovery and notices from Discord; defaults to "en-US" |default| :data:`None`
1097
        features : Optional[List[:class:`GuildFeature`]]
1098
            Enabled guild features |default| :data:`None`
1099
        description : Optional[:class:`str`]
1100
            The description for the guild, if the guild is discoverable |default| :data:`None`
1101
1102
        Returns
1103
        -------
1104
        :class:`~pincer.objects.guild.Guild`
1105
            The modified guild object.
1106
        """
1107
        ...
1108
1109
    async def edit(self, **kwargs) -> Guild:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
1110
        g = await self._http.patch(f"guilds/{self.id}", data=kwargs)
1111
        return Guild.from_dict(construct_client_dict(self._client, g))
1112
1113
    async def preview(self) -> GuildPreview:
1114
        """|coro|
1115
        Previews the guild.
1116
1117
        Returns
1118
        -------
1119
        :class:`~pincer.objects.guild.guild.GuildPreview`
1120
            The guild preview object.
1121
        """
1122
        data = await self._http.get(f"guilds/{self.id}/preview")
1123
        return GuildPreview.from_dict(data)
1124
1125
    async def delete(self):
1126
        """|coro|
1127
        Deletes the guild. Returns `204 No Content` on success.
1128
        """
1129
        await self._http.delete(f"guilds/{self.id}")
1130
1131
    async def prune_count(
1132
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1133
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1134
        include_roles: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1135
    ) -> int:
1136
        """|coro|
1137
        Returns the number of members that
1138
        would be removed in a prune operation.
1139
        Requires the ``KICK_MEMBERS`` permission.
1140
1141
        Parameters
1142
        ----------
1143
        days : Optional[:class:`int`]
1144
            Number of days to count prune for (1-30) |default| :data:`7`
1145
        include_roles : Optional[:class:`str`]
1146
            Comma-delimited array of Snowflakes;
1147
            role(s) to include |default| :data:`None`
1148
1149
        Returns
1150
        -------
1151
        :class:`int`
1152
            The number of members that would be removed.
1153
        """
1154
        return await self._http.get(
1155
            f"guilds/{self.id}/prune?{days=}&{include_roles=!s}"
1156
        )["pruned"]
1157
1158
    async def prune(
1159
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1160
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1161
        compute_prune_days: Optional[bool] = True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1162
        include_roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1163
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1164
    ) -> int:
1165
        """|coro|
1166
        Prunes members from the guild. Requires the ``KICK_MEMBERS`` permission.
1167
1168
        Parameters
1169
1170
        Parameters
1171
        ----------
1172
        days : Optional[:class:`int`]
1173
            Number of days to prune (1-30) |default| :data:`7`
1174
        compute_prune_days : Optional[:class:`bool`]
1175
            Whether ``pruned`` is returned, discouraged for large guilds
1176
            |default| :data:`True`
1177
        include_roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1178
            role(s) to include |default| :data:`None`
1179
        reason : Optional[:class:`str`]
1180
            Reason for the prune |default| :data:`None`
1181
1182
        Returns
1183
        -------
1184
        :class:`int`
1185
            The number of members that were removed.
1186
        """
1187
        return await self._http.post(
1188
            f"guilds/{self.id}/prune",
1189
            data={
1190
                "days": days,
1191
                "compute_prune_days": compute_prune_days,
1192
                "include_roles": include_roles
1193
            },
1194
            headers=remove_none({"X-Audit-Log-Reason": reason})
1195
        )["pruned"]
1196
1197
    async def get_voice_regions(self) -> AsyncGenerator[VoiceRegion, None]:
1198
        """|coro|
1199
        Returns an async generator of voice regions.
1200
1201
        Yields
1202
        -------
1203
        AsyncGenerator[:class:`~pincer.objects.voice.VoiceRegion`, :data:`None`]
1204
            An async generator of voice regions.
1205
        """
1206
        data = await self._http.get(f"guilds/{self.id}/regions")
1207
        for voice_region_data in data:
1208
            yield VoiceRegion.from_dict(construct_client_dict(self._client, voice_region_data))
1209
1210
    async def get_invites(self) -> AsyncGenerator[Invite, None]:
1211
        """|coro|
1212
        Returns an async generator of invites for the guild.
1213
        Requires the ``MANAGE_GUILD`` permission.
1214
1215
        Yields
1216
        -------
1217
        AsyncGenerator[:class:`~pincer.objects.invite.Invite`, :data:`None`]
1218
            An async generator of invites.
1219
        """
1220
        data = await self._http.get(f"guilds/{self.id}/invites")
1221
        for invite_data in data:
1222
            yield Invite.from_dict(construct_client_dict(self._client, invite_data))
1223
1224
    async def get_integrations(self) -> AsyncGenerator[Integration, None]:
1225
        """|coro|
1226
        Returns an async generator of integrations for the guild.
1227
        Requires the ``MANAGE_GUILD`` permission.
1228
1229
        Yields
1230
        -------
1231
        AsyncGenerator[:class:`~pincer.objects.integration.Integration`, :data:`None`]
1232
            An async generator of integrations.
1233
        """
1234
        data = await self._http.get(f"guilds/{self.id}/integrations")
1235
        for integration_data in data:
1236
            yield Integration.from_dict(construct_client_dict(self._client, integration_data))
1237
1238
    async def delete_integration(
1239
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1240
        integration: Integration,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1241
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1242
    ):
1243
        """|coro|
1244
        Deletes an integration.
1245
        Requires the ``MANAGE_GUILD`` permission.
1246
1247
        Parameters
1248
        ----------
1249
        integration : :class:`~pincer.objects.integration.Integration`
1250
            The integration to delete.
1251
        reason : Optional[:class:`str`]
1252
            Reason for the deletion |default| :data:`None`
1253
        """
1254
        await self._http.delete(
1255
            f"guilds/{self.id}/integrations/{integration.id}",
1256
            headers=remove_none({"X-Audit-Log-Reason": reason})
1257
        )
1258
1259
    async def get_widget_settings(self) -> GuildWidget:
1260
        """|coro|
1261
        Returns the guild widget settings.
1262
        Requires the ``MANAGE_GUILD`` permission.
1263
1264
        Returns
1265
        -------
1266
        :class:`~pincer.objects.guild.widget.GuildWidget`
1267
            The guild widget settings.
1268
        """
1269
        return GuildWidget.from_dict(
1270
            construct_client_dict(
1271
                self._client,
1272
                await self._http.get(f"guilds/{self.id}/widget")
1273
            )
1274
        )
1275
1276
    async def modify_widget(
1277
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1278
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1279
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1280
    ) -> GuildWidget:
1281
        """|coro|
1282
        Modifies the guild widget for the guild.
1283
        Requires the ``MANAGE_GUILD`` permission.
1284
1285
        Parameters
1286
        ----------
1287
        reason : Optional[:class:`str`]
1288
            Reason for the modification |default| :data:`None`
1289
        \\*\\*kwargs
1290
            The widget settings to modify
1291
1292
        Returns
1293
        -------
1294
        :class:`~pincer.objects.guild.widget.GuildWidget`
1295
            The updated GuildWidget object
1296
        """
1297
        data = await self._http.patch(
1298
            f"guilds/{self.id}/widget",
1299
            data=kwargs,
1300
            headers=remove_none({"X-Audit-Log-Reason": reason})
1301
        )
1302
        return GuildWidget.from_dict(construct_client_dict(self._client, data))
1303
1304
    async def get_widget(self) -> Dict[str, JSONSerializable]:
1305
        """|coro|
1306
        Returns the widget for the guild
1307
        """
1308
        return await self._http.get(f"guilds/{self.id}/widget.json")
1309
1310
    @property
1311
    async def vanity_url(self) -> Invite:
1312
        """|coro|
1313
        Returns the Vanity URL for the guild.
1314
        Requires the ``MANAGE_GUILD`` permission.
1315
        ``code`` will be null if a vanity URL has not been set.
1316
1317
        Returns
1318
        -------
1319
        :class:`~pincer.objects.guild.invite.Invite`
1320
            The vanity url for the guild.
1321
        """
1322
        data = await self._http.get(f"guilds/{self.id}/vanity-url")
1323
        return Invite.from_dict(construct_client_dict(self._client, data))
1324
1325
    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...
1326
        """|coro|
1327
        Returns a PNG image widget for the guild.
1328
        Requires no permissions or authentication.
1329
1330
        Widget Style Options
1331
        -------------------
1332
        * [``shield``](https://discord.com/api/guilds/81384788765712384/widget.png?style=shield)
1333
          shield style widget with Discord icon and guild members online count
1334
        * [``banner1``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner1)
1335
          large image with guild icon, name and online count.
1336
          "POWERED BY DISCORD" as the footer of the widget
1337
        * [``banner2``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner2)
1338
          smaller widget style with guild icon, name and online count.
1339
          Split on the right with Discord logo
1340
        * [``banner3``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner3)
1341
          large image with guild icon, name and online count.
1342
          In the footer, Discord logo on the
1343
          left and "Chat Now" on the right
1344
        * [``banner4``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner4)
1345
          large Discord logo at the top of the widget.
1346
          Guild icon, name and online count in the middle portion
1347
          of the widget and a "JOIN MY SERVER" button at the bottom
1348
1349
        Parameters
1350
        ----------
1351
        style : Optional[:class:`str`]
1352
            Style of the widget image returned |default| :data:`"shield"`
1353
1354
        Returns
1355
        -------
1356
        :class:`str`
1357
            A PNG image of the guild widget.
1358
        """
1359
        return await self._http.get(f"guilds/{self.id}/widget.png?{style=!s}")
1360
1361
    async def get_welcome_screen(self) -> WelcomeScreen:
1362
        """Returns the welcome screen for the guild.
1363
1364
        Returns
1365
        -------
1366
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1367
            The welcome screen for the guild.
1368
        """
1369
        data = await self._http.get(f"guilds/{self.id}/welcome-screen")
1370
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1371
1372
    async def modify_welcome_screen(
1373
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1374
        enabled: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1375
        welcome_channels: Optional[List[WelcomeScreenChannel]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1376
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1377
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1378
    ) -> WelcomeScreen:
1379
        """|coro|
1380
        Modifies the guild's Welcome Screen.
1381
        Requires the ``MANAGE_GUILD`` permission.
1382
1383
        Parameters
1384
        ----------
1385
        enabled : Optional[:class:`bool`]
1386
            Whether the welcome screen is enabled |default| :data:`None`
1387
        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...
1388
            Channels linked in the welcome screen and
1389
            their display options |default| :data:`None`
1390
        description : Optional[:class:`str`]
1391
            The server description to show
1392
            in the welcome screen |default| :data:`None`
1393
        reason : Optional[:class:`str`]
1394
            Reason for the modification |default| :data:`None`
1395
1396
        Returns
1397
        -------
1398
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1399
            The updated WelcomeScreen object
1400
        """
1401
        data = await self._http.patch(
1402
            f"guilds/{self.id}/welcome-screen",
1403
            data={
1404
                "enabled": enabled,
1405
                "welcome_channels": welcome_channels,
1406
                "description": description
1407
            },
1408
            headers=remove_none({"X-Audit-Log-Reason": reason})
1409
        )
1410
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1411
1412
    async def modify_current_user_voice_state(
1413
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1414
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1415
        suppress: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1416
        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...
1417
    ):
1418
        """|coro|
1419
        Updates the current user's voice state.
1420
1421
        There are currently several caveats for this endpoint:
1422
        * ``channel_id`` must currently point to a stage channel
1423
        * current user must already have joined ``channel_id``
1424
        * You must have the ``MUTE_MEMBERS`` permission to
1425
          unsuppress yourself. You can always suppress yourself.
1426
        * You must have the ``REQUEST_TO_SPEAK`` permission to request
1427
          to speak. You can always clear your own request to speak.
1428
        * You are able to set ``request_to_speak_timestamp`` to any
1429
          present or future time.
1430
1431
        Parameters
1432
        ----------
1433
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1434
            The ID of the channel the user is currently in
1435
        suppress : Optional[:class:`bool`]
1436
            Toggles the user's suppress state |default| :data:`None`
1437
        request_to_speak_timestamp : Optional[:class:`~pincer.utils.timestamp.Timestamp`]
1438
            Sets the user's request to speak
1439
        """
1440
        await self._http.patch(
1441
            f"guilds/{self.id}/voice-states/@me",
1442
            data={
1443
                "channel_id": channel_id,
1444
                "suppress": suppress,
1445
                "request_to_speak_timestamp": request_to_speak_timestamp
1446
            }
1447
        )
1448
1449
    async def modify_user_voice_state(
1450
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1451
        user: User,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1452
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1453
        suppress: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1454
    ):
1455
        """|coro|
1456
        Updates another user's voice state.
1457
1458
        There are currently several caveats for this endpoint:
1459
        * ``channel_id`` must currently point to a stage channel
1460
        * User must already have joined ``channel_id``
1461
        * You must have the ``MUTE_MEMBERS`` permission.
1462
          (Since suppression is the only thing that is available currently.)
1463
        * When unsuppressed, non-bot users will have their
1464
          ``request_to_speak_timestamp`` set to the current time.
1465
          Bot users will not.
1466
        * When suppressed, the user will have their
1467
          ``request_to_speak_timestamp`` removed.
1468
1469
        Parameters
1470
        ----------
1471
        user : :class:`~pincer.objects.guild.member.Member`
1472
            The user to update
1473
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1474
            The ID of the channel the user is currently in
1475
        suppress : Optional[:class:`bool`]
1476
            Toggles the user's suppress state |default| :data:`None`
1477
        """
1478
        await self._http.patch(
1479
            f"guilds/{self.id}/voice-states/{user.id}",
1480
            data={
1481
                "channel_id": channel_id,
1482
                "suppress": suppress
1483
            }
1484
        )
1485
1486
    async def get_audit_log(self) -> AuditLog:
1487
        """|coro|
1488
        Returns an audit log object for the guild.
1489
        Requires the ``VIEW_AUDIT_LOG`` permission.
1490
1491
        Returns
1492
        -------
1493
        :class:`~pincer.objects.guild.audit_log.AuditLog`
1494
            The audit log object for the guild.
1495
        """
1496
        return AuditLog.from_dict(
1497
            construct_client_dict(
1498
                self._client,
1499
                await self._http.get(f"guilds/{self.id}/audit-logs")
1500
            )
1501
        )
1502
1503
    async def get_emojis(self) -> AsyncGenerator[Emoji, None]:
1504
        """|coro|
1505
        Returns an async generator of the emojis in the guild.
1506
1507
        Yields
1508
        ------
1509
        :class:`~pincer.objects.guild.emoji.Emoji`
1510
            The emoji object.
1511
        """
1512
        data = await self._http.get(f"guilds/{self.id}/emojis")
1513
        for emoji_data in data:
1514
            yield Emoji.from_dict(
1515
                construct_client_dict(self._client, emoji_data)
1516
            )
1517
1518
    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...
1519
        """|coro|
1520
        Returns an emoji object for the given ID.
1521
1522
        Parameters
1523
        ----------
1524
        id : :class:`~pincer.utils.snowflake.Snowflake`
1525
            The ID of the emoji
1526
1527
        Returns
1528
        -------
1529
        :class:`~pincer.objects.guild.emoji.Emoji`
1530
            The emoji object.
1531
        """
1532
        return Emoji.from_dict(
1533
            construct_client_dict(
1534
                self._client,
1535
                await self._http.get(f"guilds/{self.id}/emojis/{id}")
1536
            )
1537
        )
1538
1539
    async def create_emoji(
1540
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1541
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1542
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1543
        image: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1544
        roles: List[Snowflake],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1545
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1546
    ) -> Emoji:
1547
        """|coro|
1548
        Creates a new emoji for the guild.
1549
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1550
1551
        Emojis and animated emojis have a maximum file size of 256kb.
1552
        Attempting to upload an emoji larger than this limit will fail.
1553
1554
        Parameters
1555
        ----------
1556
        name : :class:`str`
1557
            Name of the emoji
1558
        image : :class:`str`
1559
            The 128x128 emoji image data
1560
        roles : List[:class:`~pincer.utils.snowflake.Snowflake`]
1561
            Roles allowed to use this emoji
1562
        reason : Optional[:class:`str`]
1563
            The reason for creating the emoji |default| :data:`None`
1564
1565
        Returns
1566
        -------
1567
        :class:`~pincer.objects.guild.emoji.Emoji`
1568
            The newly created emoji object.
1569
        """
1570
        data = await self._http.post(
1571
            f"guilds/{self.id}/emojis",
1572
            data={
1573
                "name": name,
1574
                "image": image,
1575
                "roles": roles
1576
            },
1577
            headers=remove_none({"X-Audit-Log-Reason": reason})
1578
        )
1579
        return Emoji.from_dict(
1580
            construct_client_dict(self._client, data)
1581
        )
1582
1583
    async def edit_emoji(
1584
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1585
        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...
1586
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1587
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1588
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1589
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1590
    ) -> Emoji:
1591
        """|coro|
1592
        Modifies the given emoji.
1593
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1594
1595
        Parameters
1596
        ----------
1597
        id : :class:`~pincer.utils.snowflake.Snowflake`
1598
            The ID of the emoji
1599
        name : Optional[:class:`str`]
1600
            Name of the emoji |default| :data:`None`
1601
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1602
            Roles allowed to use this emoji |default| :data:`None`
1603
        reason : Optional[:class:`str`]
1604
            The reason for editing the emoji |default| :data:`None`
1605
1606
        Returns
1607
        -------
1608
        :class:`~pincer.objects.guild.emoji.Emoji`
1609
            The modified emoji object.
1610
        """
1611
        data = await self._http.patch(
1612
            f"guilds/{self.id}/emojis/{id}",
1613
            data={
1614
                "name": name,
1615
                "roles": roles
1616
            },
1617
            headers=remove_none({"X-Audit-Log-Reason": reason})
1618
        )
1619
        return Emoji.from_dict(
1620
            construct_client_dict(self._client, data)
1621
        )
1622
1623
    async def delete_emoji(
1624
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1625
        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...
1626
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1627
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1628
    ):
1629
        """|coro|
1630
        Deletes the given emoji.
1631
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1632
1633
        Parameters
1634
        ----------
1635
        id : :class:`~pincer.utils.snowflake.Snowflake`
1636
            The ID of the emoji
1637
        reason : Optional[:class:`str`]
1638
            The reason for deleting the emoji |default| :data:`None`
1639
        """
1640
        await self._http.delete(
1641
            f"guilds/{self.id}/emojis/{id}",
1642
            headers=remove_none({"X-Audit-Log-Reason": reason})
1643
        )
1644
1645
    async def get_templates(self) -> AsyncGenerator[GuildTemplate, None]:
1646
        """|coro|
1647
        Returns an async generator of the guild templates.
1648
1649
        Yields
1650
        -------
1651
        AsyncGenerator[:class:`~pincer.objects.guild.template.GuildTemplate`, :data:`None`]
1652
            The guild template object.
1653
        """
1654
        data = await self._http.get(f"guilds/{self.id}/templates")
1655
        for template_data in data:
1656
            yield GuildTemplate.from_dict(
1657
                construct_client_dict(self._client, template_data)
1658
            )
1659
1660
    async def create_template(
1661
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1662
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1663
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1664
    ) -> GuildTemplate:
1665
        """|coro|
1666
        Creates a new template for the guild.
1667
        Requires the ``MANAGE_GUILD`` permission.
1668
1669
        Parameters
1670
        ----------
1671
        name : :class:`str`
1672
            Name of the template (1-100 characters)
1673
        description : Optional[:class:`str`]
1674
            Description of the template
1675
            (0-120 characters) |default| :data:`None`
1676
        Returns
1677
        -------
1678
        :class:`~pincer.objects.guild.template.GuildTemplate`
1679
            The newly created template object.
1680
        """
1681
        data = await self._http.post(
1682
            f"guilds/{self.id}/templates",
1683
            data={
1684
                "name": name,
1685
                "description": description
1686
            }
1687
        )
1688
        return GuildTemplate.from_dict(
1689
            construct_client_dict(self._client, data)
1690
        )
1691
1692
    async def sync_template(
1693
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1694
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1695
    ) -> GuildTemplate:
1696
        """|coro|
1697
        Syncs the given template.
1698
        Requires the ``MANAGE_GUILD`` permission.
1699
1700
        Parameters
1701
        ----------
1702
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1703
            The template to sync
1704
1705
        Returns
1706
        -------
1707
        :class:`~pincer.objects.guild.template.GuildTemplate`
1708
            The synced template object.
1709
        """
1710
        data = await self._http.put(
1711
            f"guilds/{self.id}/templates/{template.code}"
1712
        )
1713
        return GuildTemplate.from_dict(
1714
            construct_client_dict(self._client, data)
1715
        )
1716
1717
    async def edit_template(
1718
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1719
        template: GuildTemplate,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1720
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1721
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1722
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1723
    ) -> GuildTemplate:
1724
        """|coro|
1725
        Modifies the template's metadata.
1726
        Requires the ``MANAGE_GUILD`` permission.
1727
1728
        Parameters
1729
        ----------
1730
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1731
            The template to edit
1732
        name : Optional[:class:`str`]
1733
            Name of the template (1-100 characters)
1734
            |default| :data:`None`
1735
        description : Optional[:class:`str`]
1736
            Description of the template (0-120 characters)
1737
            |default| :data:`None`
1738
1739
        Returns
1740
        -------
1741
        :class:`~pincer.objects.guild.template.GuildTemplate`
1742
            The edited template object.
1743
        """
1744
        data = await self._http.patch(
1745
            f"guilds/{self.id}/templates/{template.code}",
1746
            data={
1747
                "name": name,
1748
                "description": description
1749
            }
1750
        )
1751
        return GuildTemplate.from_dict(
1752
            construct_client_dict(self._client, data)
1753
        )
1754
1755
    async def delete_template(
1756
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1757
        template: GuildTemplate
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1758
    ) -> GuildTemplate:
1759
        """|coro|
1760
        Deletes the given template.
1761
        Requires the ``MANAGE_GUILD`` permission.
1762
1763
        Parameters
1764
        ----------
1765
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1766
            The template to delete
1767
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1768
        Returns
1769
        -------
1770
        :class:`~pincer.objects.guild.template.GuildTemplate`
1771
            The deleted template object.
1772
        """
1773
        data = await self._http.delete(
1774
            f"guilds/{self.id}/templates/{template.code}"
1775
        )
1776
        return GuildTemplate.from_dict(
1777
            construct_client_dict(self._client, data)
1778
        )
1779
1780
    @classmethod
1781
    def from_dict(cls, data) -> Guild:
1782
        """
1783
        Parameters
1784
        ----------
1785
        data : :class:`Dict`
1786
            Guild data received from the discord API.
1787
        Returns
1788
        -------
1789
        :class:`~pincer.objects.guild.guild.Guild`
1790
            The new guild object.
1791
        Raises
1792
        :class:`~pincer.exceptions.UnavailableGuildError`
1793
            The guild is unavailable due to a discord outage.
1794
        """
1795
        if data.get("unavailable", False):
1796
            raise UnavailableGuildError(
1797
                f"Guild \"{data['id']}\" is unavailable due to a discord"
1798
                " outage."
1799
            )
1800
1801
        return super().from_dict(data)
1802
1803
1804
@dataclass
1805
class UnavailableGuild(APIObject):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
1806
    id: Snowflake
1807
    unavailable: bool = True
1808