Passed
Pull Request — main (#393)
by Yohann
03:30 queued 01:19
created

pincer.objects.guild.guild.Guild.get_invite()   A

Complexity

Conditions 1

Size

Total Lines 16
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 16
rs 10
c 0
b 0
f 0
cc 1
nop 2
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 (1942/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 aiohttp import FormData
11
12
from .channel import Channel, Thread
13
from ..message.file import File
14
from ...exceptions import UnavailableGuildError
15
from ...utils.api_object import APIObject
16
from ...utils.types import MISSING
17
18
if TYPE_CHECKING:
19
    from typing import Any, Dict, List, Optional, Tuple, Union, Generator
20
21
    from collections.abc import AsyncIterator
22
    from .audit_log import AuditLog
23
    from .ban import Ban
24
    from .channel import ChannelType
25
    from .member import GuildMember
26
    from .features import GuildFeature
27
    from .invite import Invite
28
    from .overwrite import Overwrite
29
    from .role import Role
30
    from .scheduled_events import ScheduledEvent
31
    from .stage import StageInstance
32
    from .template import GuildTemplate
33
    from .welcome_screen import WelcomeScreen, WelcomeScreenChannel
34
    from .widget import GuildWidget
35
    from .webhook import Webhook
36
    from ..user.user import User
37
    from ..user.integration import Integration
38
    from ..voice.region import VoiceRegion
39
    from ..events.presence import PresenceUpdateEvent
40
    from ..message.emoji import Emoji
41
    from ..message.sticker import Sticker
42
    from ..user.voice_state import VoiceState
43
    from ...client import Client
44
    from ...utils.timestamp import Timestamp
45
    from ...utils.types import APINullable, JSONSerializable
46
    from ...utils.snowflake import Snowflake
47
48
49
class PremiumTier(IntEnum):
50
    """Represents the boost tier of a guild.
51
    Attributes
52
    ----------
53
    NONE:
54
        Guild has not unlocked any Server Boost perks.
55
    TIER_1:
56
        Guild has unlocked Server Boost level 1 perks.
57
    TIER_2:
58
        Guild has unlocked Server Boost level 2 perks.
59
    TIER_3:
60
        Guild has unlocked Server Boost level 3 perks.
61
    """
62
63
    NONE = 0
64
    TIER_1 = 1
65
    TIER_2 = 2
66
    TIER_3 = 3
67
68
69
class GuildNSFWLevel(IntEnum):
70
    """Represents the NSFW level of a guild.
71
    Attributes
72
    ----------
73
    DEFAULT:
74
        Default NSFW level.
75
    EXPLICIT:
76
        Explicit NSFW level.
77
    SAFE:
78
        SAFE NSFW level.
79
    AGE_RESTRICTED:
80
        Age restricted NSFW level.
81
    """
82
83
    DEFAULT = 0
84
    EXPLICIT = 1
85
    SAFE = 2
86
    AGE_RESTRICTED = 3
87
88
89
class ExplicitContentFilterLevel(IntEnum):
90
    """Represents the filter content level of a guild.
91
    Attributes
92
    ----------
93
    DISABLED:
94
        Media content will not be scanned.
95
    MEMBERS_WITHOUT_ROLES:
96
        Media content sent by members without roles will be scanned.
97
    ALL_MEMBERS:
98
        Media content sent by all members will be scanned.
99
    """
100
101
    DISABLED = 0
102
    MEMBERS_WITHOUT_ROLES = 1
103
    ALL_MEMBERS = 2
104
105
106
class MFALevel(IntEnum):
107
    """Represents the multi-factor authentication level of a guild.
108
    Attributes
109
    ----------
110
    NONE:
111
        Guild has no MFA/2FA requirement for moderation actions.
112
    ELEVATED:
113
        Guild has a 2FA requirement for moderation actions
114
    """
115
116
    NONE = 0
117
    ELEVATED = 1
118
119
120
class VerificationLevel(IntEnum):
121
    """Represents the verification level of a guild.
122
    Attributes
123
    ----------
124
    NONE:
125
        Unrestricted.
126
    LOW:
127
        Must have verified email on account.
128
    MEDIUM:
129
        Must be registered on Discord for longer than 5 minutes.
130
    HIGH:
131
        Must be a member of the server for longer than 10 minutes.
132
    VERY_HIGH:
133
        Must have a verified phone number.
134
    """
135
136
    NONE = 0
137
    LOW = 1
138
    MEDIUM = 2
139
    HIGH = 3
140
    VERY_HIGH = 4
141
142
143
class DefaultMessageNotificationLevel(IntEnum):
144
    """Represents the default message notification level of a guild.
145
    Attributes
146
    ----------
147
    ALL_MESSAGES:
148
        Members will receive notifications for all messages by default.
149
    ONLY_MENTIONS:
150
        Members will receive notifications only for messages that @mention them by default.
151
    """
152
153
    # noqa: E501
154
    ALL_MESSAGES = 0
155
    ONLY_MENTIONS = 1
156
157
158
class SystemChannelFlags(IntEnum):
159
    """Represents the system channel flags of a guild.
160
    Attributes
161
    ----------
162
    SUPPRESS_JOIN_NOTIFICATIONS:
163
        Suppress member join notifications.
164
    SUPPRESS_PREMIUM_SUBSCRIPTIONS:
165
        Suppress server boost notifications.
166
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS:
167
        Suppress server setup tips.
168
    SUPPRESS_JOIN_NOTIFICATION_REPLIES:
169
        Hide member join sticker reply buttons
170
    """
171
172
    SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0
173
    SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
174
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS = 1 << 2
175
    SUPPRESS_JOIN_NOTIFICATION_REPLIES = 1 << 3
176
177
178
@dataclass(repr=False)
179
class GuildPreview(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (10/7)
Loading history...
180
    """Represents a guild preview.
181
    Attributes
182
    ----------
183
    id: :class:`Snowflake`
184
        The guild ID.
185
    name: :class:`str`
186
        The guild name.
187
    icon: :class:`str`
188
        The guild icon hash.
189
    splash: :class:`str`
190
        The guild splash hash.
191
    discovery_splash: :class:`str`
192
        The guild discovery splash hash.
193
    emojis: :class:`List[Emoji]`
194
        The guild emojis.
195
    features: :class:`List[GuildFeature]`
196
        The guild features.
197
    approximate_member_count: :class:`int`
198
        The approximate member count.
199
    approximate_presence_count: :class:`int`
200
        The approximate number of online members in this guild
201
    description: :class:`str`
202
        The guild description.
203
    """
204
205
    id: Snowflake
206
    name: str
207
    emojis: List[Emoji]
208
    features: List[GuildFeature]
209
    approximate_member_count: int
210
    approximate_presence_count: int
211
212
    icon: APINullable[str] = MISSING
213
    splash: APINullable[str] = MISSING
214
    discovery_splash: APINullable[str] = MISSING
215
    description: APINullable[str] = MISSING
216
217
218
@dataclass(repr=False)
219
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 (60/20)
Loading history...
220
    """Represents a Discord guild/server in which your client resides.
221
    Attributes
222
    ----------
223
    afk_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
224
        Id of afk channel
225
    afk_timeout: :class:`int`
226
        Afk timeout in seconds
227
    application_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
228
        Application id of the guild creator if it is bot-created
229
    banner: Optional[:class:`str`]
230
        Banner hash
231
    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...
232
        Default message notifications level
233
    description: Optional[:class:`str`]
234
        The description of a Community guild
235
    discovery_splash: Optional[:class:`str`]
236
        Discovery splash hash;
237
        only present for guilds with the "DISCOVERABLE" feature
238
    emojis: List[:class:`~pincer.objects.message.emoji.Emoji`]
239
        Custom guild emojis
240
    explicit_content_filter: :class:`~pincer.objects.guild.guild.ExplicitContentFilterLevel`
241
        Explicit content filter level
242
    features: List[:class:`~pincer.objects.guild.features.GuildFeature`]
243
        Enabled guild features
244
    id: :class:`~pincer.utils.snowflake.Snowflake`
245
        Guild id
246
    icon: Optional[:class:`str`]
247
        Icon hash
248
    mfa_level: :class:`~pincer.objects.guild.guild.MFALevel`
249
        Required MFA level for the guild
250
    name: :class:`str`
251
        Guild name (2-100 characters, excluding trailing and leading
252
        whitespace)
253
    nsfw_level: :class:`~pincer.objects.guild.guild.NSFWLevel`
254
        Guild NSFW level
255
    owner_id: :class:`~pincer.utils.snowflake.Snowflake`
256
        Id of owner
257
    preferred_locale: :class:`str`
258
        The preferred locale of a Community guild;
259
        used in server discovery and notices from Discord;
260
        defaults to "en-US"
261
    premium_tier: :class:`~pincer.objects.guild.guild.PremiumTier`
262
        Premium tier (Server Boost level)
263
    public_updates_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
264
        The id of the channel where admins
265
        and moderators of Community guilds receive notices from Discord
266
    roles: List[:class:`~pincer.objects.guild.role.Role`]
267
        Roles in the guild
268
    rules_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
269
        The id of the channel where Community guilds can display rules
270
        and/or guidelines
271
    splash: Optional[:class:`str`]
272
        Splash hash
273
    system_channel_flags: :class:`~pincer.objects.guild.guild.SystemChannelFlags`
274
        System channel flags
275
    system_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
276
        The id of the channel where guild notices
277
        such as welcome messages and boost events are posted
278
    vanity_url_code: Optional[:class:`str`]
279
        The vanity url code for the guild
280
    verification_level: :class:`~pincer.objects.guild.guild.VerificationLevel`
281
        Verification level required for the guild
282
    approximate_member_count: APINullable[:class:`int`]
283
        Approximate number of members in this guild, returned from the
284
        `GET /guilds/<id>` endpoint when with_counts is true
285
    approximate_presence_count: APINullable[:class:`int`]
286
        Approximate number of non-offline members in this guild,
287
        returned from the `GET /guilds/<id>`
288
        endpoint when with_counts is true
289
    channels: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
290
        Channels in the guild
291
    icon_hash: APINullable[Optional[:class:`str`]]
292
        Icon hash, returned when in the template object
293
    joined_at: APINullable[:class:`~pincer.utils.timestamp.Timestamp`]
294
        When this guild was joined at
295
    large: APINullable[:class:`bool`]
296
        True if this is considered a large guild
297
    max_members: APINullable[:class:`int`]
298
        The maximum number of members for the guild
299
    max_presences: APINullable[Optional[:class:`int`]]
300
        The maximum number of presences for the guild
301
        (null is always returned, apart from the largest of guilds)
302
    max_video_channel_users: APINullable[:class:`int`]
303
        The maximum amount of users in a video channel
304
    members: APINullable[List[:class:`~pincer.objects.guild.member.GuildMember`]]
305
        Users in the guild
306
    member_count: APINullable[:class:`bool`]
307
        Total number of members in this guild
308
    nsfw: APINullable[:class:`bool`]
309
        Boolean if the server is NSFW
310
    owner: APINullable[:class:`bool`]
311
        True if the user is the owner of the guild
312
    permissions: APINullable[:class:`str`]
313
        Total permissions for the user in the guild
314
        (excludes overwrites)
315
    premium_subscription_count: APINullable[:class:`int`]
316
        The number of boosts this guild currently has
317
    presences: APINullable[List[:class:`~pincer.objects.events.presence.PresenceUpdateEvent`]]
318
        Presences of the members in the guild,
319
        will only include non-offline members if the size is greater
320
        than large threshold
321
    stage_instances: APINullable[List[:class:`~pincer.objects.guild.stage.StageInstance`]]
322
        Stage instances in the guild
323
    stickers: Optional[List[:class:`~pincer.objects.message.sticker.Sticker`]]
324
        Custom guild stickers
325
    region: APINullable[Optional[:class:`str`]]
326
        Voice region id for the guild (deprecated)
327
    threads: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
328
        All active threads in the guild that current user
329
        has permission to view
330
    unavailable: APINullable[:class:`bool`]
331
        True if this guild is unavailable due to an outage
332
    voice_states: APINullable[List[:class:`~pincer.objects.user.voice_state.VoiceState`]]
333
        States of members currently in voice channels;
334
        lacks the guild_id key
335
    widget_enabled: APINullable[:class:`bool`]
336
        True if the server widget is enabled
337
    widget_channel_id: APINullable[Optional[:class:`~pincer.utils.snowflake.Snowflake`]]
338
        The channel id that the widget will generate an invite to,
339
        or null if set to no invite
340
    welcome_screen: APINullable[:class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`]
341
        The welcome screen of a Community guild, shown to new members,
342
        returned in an Invite's guild object
343
    """
344
345
    # noqa: E501
346
    features: List[GuildFeature]
347
    id: Snowflake
348
    name: str
349
    nsfw_level: GuildNSFWLevel
350
    verification_level: VerificationLevel
351
352
    # Guild invites missing
353
    system_channel_flags: APINullable[SystemChannelFlags] = MISSING
354
    explicit_content_filter: APINullable[ExplicitContentFilterLevel] = MISSING
355
    premium_tier: APINullable[PremiumTier] = MISSING
356
    default_message_notifications: APINullable[
357
        DefaultMessageNotificationLevel
358
    ] = MISSING
359
    mfa_level: APINullable[MFALevel] = MISSING
360
    owner_id: APINullable[Snowflake] = MISSING
361
    afk_timeout: APINullable[int] = MISSING
362
    emojis: APINullable[List[Emoji]] = MISSING
363
    preferred_locale: APINullable[str] = MISSING
364
    roles: APINullable[List[Role]] = MISSING
365
366
    guild_scheduled_events: APINullable[List[ScheduledEvent]] = MISSING
367
    lazy: APINullable[bool] = MISSING
368
    premium_progress_bar_enabled: APINullable[bool] = MISSING
369
    guild_hashes: APINullable[Dict] = MISSING
370
    afk_channel_id: APINullable[Snowflake] = MISSING
371
    application_id: APINullable[Snowflake] = MISSING
372
    embedded_activities: APINullable[List] = MISSING
373
    banner: APINullable[str] = MISSING
374
    description: APINullable[str] = MISSING
375
    discovery_splash: APINullable[str] = MISSING
376
    icon: APINullable[str] = MISSING
377
    public_updates_channel_id: APINullable[Snowflake] = MISSING
378
    rules_channel_id: APINullable[Snowflake] = MISSING
379
    splash: APINullable[str] = MISSING
380
    system_channel_id: APINullable[Snowflake] = MISSING
381
    vanity_url_code: APINullable[str] = MISSING
382
383
    application_command_counts: APINullable[Dict] = MISSING
384
    application_command_count: APINullable[int] = MISSING
385
    approximate_member_count: APINullable[int] = MISSING
386
    approximate_presence_count: APINullable[int] = MISSING
387
    channels: APINullable[List[Channel]] = field(default_factory=list)
388
    # 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...
389
    hub_type: APINullable[Any] = MISSING
390
    icon_hash: APINullable[Optional[str]] = MISSING
391
    joined_at: APINullable[Timestamp] = MISSING
392
    large: APINullable[bool] = MISSING
393
    max_members: APINullable[int] = MISSING
394
    max_presences: APINullable[Optional[int]] = MISSING
395
    max_video_channel_users: APINullable[int] = MISSING
396
    members: APINullable[List[GuildMember]] = MISSING
397
    member_count: APINullable[bool] = MISSING
398
    nsfw: APINullable[bool] = MISSING
399
    # Note: This is missing from discord's docs but in the api
400
    owner: APINullable[bool] = MISSING
401
    permissions: APINullable[str] = MISSING
402
    premium_subscription_count: APINullable[int] = MISSING
403
    presences: APINullable[List[PresenceUpdateEvent]] = MISSING
404
    stage_instances: APINullable[List[StageInstance]] = MISSING
405
    stickers: APINullable[List[Sticker]] = MISSING
406
    region: APINullable[Optional[str]] = MISSING
407
    threads: APINullable[List[Channel]] = MISSING
408
    # Guilds are considered available unless otherwise specified
409
    unavailable: APINullable[bool] = False
410
    voice_states: APINullable[List[VoiceState]] = MISSING
411
    widget_enabled: APINullable[bool] = MISSING
412
    widget_channel_id: APINullable[Optional[Snowflake]] = MISSING
413
    welcome_screen: APINullable[WelcomeScreen] = MISSING
414
415
    @classmethod
416
    async def from_id(
417
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
418
        client: Client,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
419
        _id: Union[int, Snowflake],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
420
        with_counts: bool = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
421
    ) -> Guild:
422
        """
423
        Parameters
424
        ----------
425
        client : :class:`~pincer.Client`
426
            Client object to use the http gateway from.
427
        _id : :class:`~pincer.utils.snowflake.Snowflake`
428
            Guild ID.
429
        Returns
430
        -------
431
        :class:`~pincer.objects.guild.guild.Guild`
432
            The new guild object.
433
        """
434
        data = await client.http.get(
435
            f"/guilds/{_id}",
436
            # Yarl don't support boolean params
437
            params={"with_counts": "true" if with_counts else None},
438
        )
439
        channel_data = await client.http.get(f"/guilds/{_id}/channels")
440
441
        data["channels"]: List[Channel] = [
442
            Channel.from_dict(i) for i in (channel_data or [])
443
        ]
444
445
        return Guild.from_dict(data)
446
447
    async def get_member(self, _id: int) -> GuildMember:
448
        """|coro|
449
        Fetches a GuildMember from its identifier
450
451
        Parameters
452
        ----------
453
        _id: int
454
            The id of the guild member which should be fetched from the Discord
455
            gateway.
456
        Returns
457
        -------
458
        :class:`~pincer.objects.guild.member.GuildMember`
459
            A GuildMember object.
460
        """
461
        return await GuildMember.from_id(self._client, self.id, _id)
462
463
    @overload
464
    async def modify_member(
465
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
466
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
467
        _id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
468
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
469
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
470
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
471
        deaf: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
472
        channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
473
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
474
        communication_disabled_until: Optional[Timestamp] = MISSING,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
475
    ) -> GuildMember:
476
        """|coro|
477
        Modifies a member in the guild from its identifier and based on the
478
        keyword arguments provided.
479
        Parameters
480
        ----------
481
        _id : int
482
            Id of the member to modify
483
        nick : Optional[:class:`str`]
484
            New nickname for the member |default| :data:`None`
485
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake]]
486
            New roles for the member |default| :data:`None`
487
        mute : Optional[:class:`bool`]
488
            Whether the member is muted |default| :data:`None`
489
        deaf : Optional[:class:`bool`]
490
            Whether the member is deafened |default| :data:`None`
491
        channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake]
492
            Voice channel id to move to |default| :data:`None`
493
        reason : Optional[:class:`str`]
494
            audit log reason |default| :data:`None`
495
        communication_disabled_until : Optional[Timestamp]
496
            When the member can communicate again, requires ``MODERATE_MEMBERS``
497
            permissions. Set to ``None`` to disable the timeout.
498
499
        Returns
500
        -------
501
        :class:`~pincer.objects.guild.member.GuildMember`
502
            The new member object.
503
        """
504
        ...
505
506
    async def modify_member(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
507
        self, _id: int, reason=None, **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
508
    ) -> GuildMember:
509
        if kwargs.get("communication_disabled_until") is MISSING:
510
            kwargs.pop("communication_disabled_until")
511
        data = await self._http.patch(
512
            f"guilds/{self.id}/members/{_id}",
513
            data=kwargs,
514
            headers={"X-Audit-Log-Reason": reason},
515
        )
516
        return GuildMember.from_dict(data)
517
518
    @overload
519
    async def create_channel(
520
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
521
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
522
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
523
        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...
524
        topic: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
525
        bitrate: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
526
        user_limit: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
527
        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...
528
        position: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
529
        permission_overwrites: Optional[List[Overwrite]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
530
        parent_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
531
        nsfw: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
532
    ) -> Channel:
533
        """|coro|
534
        Create a new channel object for the guild.
535
536
        Parameters
537
        ----------
538
        name : str
539
            channel name (1-100 characters)
540
        type : Optional[:class:int`]
541
            the type of channel
542
        topic : Optional[:class:str`]
543
            channel topic (0-1024 characters)
544
        bitrate : Optional[:class:`int`]
545
            the bitrate (in bits) of the voice channel (voice only)
546
        user_limit : Optional[:class:`int`]
547
            the user limit of the voice channel (voice only)
548
        rate_limit_per_user : Optional[:class:`int`]
549
            amount of seconds a user has to wait
550
            before sending another message (0-21600)
551
            bots, as well as users with the permission
552
            manage_messages or manage_channel, are unaffected
553
        position : Optional[:class:`int`]
554
            sorting position of the channel
555
        permission_overwrites : Optional[List[:class:`~pincer.objects.guild.overwrite.Overwrite`]]
556
            the channel's permission overwrites
557
        parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
558
            id of the parent category for a channel
559
        nsfw : Optional[:class:`bool`]
560
            whether the channel is nsfw
561
        reason : Optional[:class:`str`]
562
            audit log reason |default| :data:`None`
563
        Returns
564
        -------
565
        :class:`~pincer.objects.guild.channel.Channel`
566
            The new channel object.
567
        """
568
        ...
569
570
    async def create_channel(self, *, reason: Optional[str] = None, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
571
        data = await self._http.post(
572
            f"guilds/{self.id}/channels",
573
            data=kwargs,
574
            headers={"X-Audit-Log-Reason": reason},
575
        )
576
        return Channel.from_dict(data)
577
578
    async def modify_channel_positions(
0 ignored issues
show
introduced by
Keyword argument before variable positional arguments list in the definition of modify_channel_positions function
Loading history...
579
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
580
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
581
        *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...
582
    ):
583
        """|coro|
584
        Create a new channel object for the guild.
585
586
        Parameters
587
        ----------
588
        reason : Optional[:class:`str`]
589
            audit log reason |default| :data:`None`
590
        \\*channel : Dict[str, Optional[Union[int, bool, :class:`~pincer.utils.snowflake.Snowflake`]
591
            Keys:
592
                - id : :class:`~pincer.utils.snowflake.Snowflake`
593
                - position : Optional[:class:`int`]
594
                - lock_permissions : Optional[:class:`bool`]
595
                - parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
596
        """
597
        await self._http.patch(
598
            f"guilds/{self.id}/channels",
599
            data=channel,
600
            headers={"X-Audit-Log-Reason": reason},
601
        )
602
603
    async def list_active_threads(
604
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
605
    ) -> Tuple[Generator[Thread], Generator[GuildMember]]:
606
        """|coro|
607
        Returns all active threads in the guild,
608
        including public and private threads.
609
610
        Returns
611
        -------
612
        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...
613
            The new member object.
614
        """
615
        data = await self._http.get(f"guilds/{self.id}/threads/active")
616
617
        threads = (Channel.from_dict(channel) for channel in data["threads"])
618
        members = (GuildMember.from_dict(member) for member in data["members"])
619
620
        return threads, members
621
622
    async def list_guild_members(
623
        self, limit: int = 1, after: int = 0
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
624
    ) -> AsyncIterator[GuildMember]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
625
        """|coro|
626
        Returns a list of guild member objects that are members of the guild.
627
628
        Parameters
629
        ----------
630
        limit : int
631
            max number of members to return (1-1000) |default| :data:`1`
632
        after : int
633
            the highest user id in the previous page |default| :data:`0`
634
635
        Yields
636
        ------
637
        :class:`~pincer.objects.guild.member.GuildMember`
638
            the guild member object that is in the guild
639
        """
640
641
        members = await self._http.get(
642
            f"guilds/{self.id}/members", params={"limit": limit, "after": after}
643
        )
644
645
        for member in members:
646
            yield GuildMember.from_dict(member)
647
648
    async def search_guild_members(
649
        self, query: str, limit: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
650
    ) -> AsyncIterator[GuildMember]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
651
        """|coro|
652
        Returns a list of guild member objects whose
653
        username or nickname starts with a provided string.
654
655
        Parameters
656
        ----------
657
        query : str
658
            Query string to match username(s) and nickname(s) against.
659
        limit : Optional[int]
660
            max number of members to return (1-1000) |default| :data:`1`
661
662
        Yields
663
        -------
664
        :class:`~pincer.objects.guild.member.GuildMember`
665
            guild member objects
666
        """
667
668
        data = await self._http.get(
669
            f"guilds/{self.id}/members/search",
670
            params={"query": query, "limit": limit},
671
        )
672
673
        for member in data:
674
            yield GuildMember.from_dict(member)
675
676
    @overload
677
    async def add_guild_member(
678
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
679
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
680
        user_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
681
        access_token: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
682
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
683
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
684
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
685
        deaf: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
686
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
687
    ) -> Optional[GuildMember]:
688
        """|coro|
689
        Adds a user to the guild, provided you have a
690
        valid oauth2 access token for the user with the guilds.join scope.
691
692
        Parameters
693
        ----------
694
        user_id : str
695
            id of the user to be added
696
        access_token : str
697
            an oauth2 access token granted with the guilds.join to
698
            the bot's application for the user you want to add to the guild
699
        nick : Optional[str]
700
            value to set users nickname to
701
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
702
            array of role ids the member is assigned
703
        mute : Optional[bool]
704
            whether the user is muted in voice channels
705
        deaf : Optional[bool]
706
            whether the user is deafened in voice channels
707
        reason : Optional[:class:`str`]
708
            audit log reason |default| :data:`None`
709
        Returns
710
        -------
711
        :class:`~pincer.objects.guild.member.GuildMember`
712
            If the user is not in the guild
713
        None
714
            If the user is in the guild
715
        """
716
717
    async def add_guild_member(self, user_id, reason=None, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
718
        data = await self._http.put(
719
            f"guilds/{self.id}/members/{user_id}",
720
            data=kwargs,
721
            headers={"X-Audit-Log-Reason": reason},
722
        )
723
724
        return GuildMember.from_dict(data) if data else None
725
726
    async def modify_current_member(
727
        self, nick: str, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
728
    ) -> GuildMember:
729
        """|coro|
730
        Modifies the current member in a guild.
731
732
        Parameters
733
        ----------
734
        nick : str
735
            value to set users nickname to
736
        reason : Optional[:class:`str`]
737
            audit log reason |default| :data:`None`
738
        Returns
739
        -------
740
        class:`~pincer.objects.guild.member.GuildMember
741
            current guild member
742
        """
743
        data = self._http.patch(
744
            f"guilds/{self.id}/members/@me",
745
            {"nick": nick},
746
            headers={"X-Audit-Log-Reason": reason},
747
        )
748
        return GuildMember.from_dict(data)
749
750
    async def add_guild_member_role(
751
        self, user_id: int, role_id: int, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
752
    ) -> None:
753
        """|coro|
754
        Adds a role to a guild member.
755
756
        Parameters
757
        ----------
758
        user_id : int
759
            id of the user to give a role to
760
        role_id : int
761
            id of a role
762
        reason : Optional[:class:`str`]
763
            audit log reason |default| :data:`None`
764
        """
765
        data = await self._http.put(
0 ignored issues
show
Unused Code introduced by
The variable data seems to be unused.
Loading history...
766
            f"guilds/{self.id}/{user_id}/roles/{role_id}",
767
            headers={"X-Audit-Log-Reason": reason},
768
        )
769
770
    async def remove_guild_member_role(
771
        self, user_id: int, role_id: int, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
772
    ):
773
        """|coro|
774
        Removes a role from a guild member.
775
776
        Parameters
777
        ----------
778
        user_id : int
779
            id of the user to remove a role from
780
        role_id : int
781
            id of a role
782
        reason : Optional[:class:`str`]
783
            audit log reason |default| :data:`None`
784
        """
785
        await self._http.delete(
786
            f"guilds/{self.id}/{user_id}/roles/{role_id}",
787
            headers={"X-Audit-Log-Reason": reason},
788
        )
789
790
    async def remove_guild_member(
791
        self, user_id: int, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
792
    ):
793
        """|coro|
794
        Remove a member from a guild.
795
796
        Parameters
797
        ----------
798
        user_id : int
799
            id of the user to remove from the guild
800
        reason : Optional[:class:`str`]
801
            audit log reason |default| :data:`None`
802
        """
803
        await self._http.delete(
804
            f"guilds/{self.id}/members/{user_id}",
805
            headers={"X-Audit-Log-Reason": reason},
806
        )
807
808
    async def ban(
809
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
810
        member_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
811
        reason: str = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
812
        delete_message_days: int = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
813
    ):
814
        """
815
        Parameters
816
        ----------
817
        member_id : :class:`int`
818
            ID of the guild member to ban.
819
        reason : Optional[:class:`str`]
820
            Reason for the kick.
821
        delete_message_days : Optional[:class:`int`]
822
            Number of days to delete messages for (0-7)
823
        """
824
        headers = {}
825
826
        if reason is not None:
827
            headers["X-Audit-Log-Reason"] = reason
828
829
        data = {}
830
831
        if delete_message_days is not None:
832
            data["delete_message_days"] = delete_message_days
833
834
        await self._http.put(
835
            f"/guilds/{self.id}/bans/{member_id}", data=data, headers=headers
836
        )
837
838
    async def kick(self, member_id: int, reason: Optional[str] = None):
839
        """|coro|
840
        Kicks a guild member.
841
        Parameters
842
        ----------
843
        member_id : :class:`int`
844
            ID of the guild member to kick.
845
        reason : Optional[:class:`str`]
846
            Reason for the kick.
847
        """
848
849
        headers = {}
850
851
        if reason is not None:
852
            headers["X-Audit-Log-Reason"] = reason
853
854
        await self._http.delete(
855
            f"/guilds/{self.id}/members/{member_id}", headers=headers
856
        )
857
858
    async def get_roles(self) -> AsyncGenerator[Role, None]:
859
        """|coro|
860
        Fetches all the roles in the guild.
861
862
        Yields
863
        -------
864
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
865
            An async generator of Role objects.
866
        """
867
        data = await self._http.get(f"guilds/{self.id}/roles")
868
        for role_data in data:
869
            yield Role.from_dict(role_data)
870
871
    @overload
872
    async def create_role(
873
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
874
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
875
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
876
        name: Optional[str] = "new role",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
877
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
878
        color: Optional[int] = 0,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
879
        hoist: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
880
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
881
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
882
        mentionable: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
883
    ) -> Role:
884
        """|coro|
885
        Creates a new role for the guild.
886
        Requires the ``MANAGE_ROLES`` permission.
887
888
        Parameters
889
        ----------
890
        reason : Optional[:class:`str`]
891
            Reason for creating the role. |default| :data:`None`
892
        name : Optional[:class:`str`]
893
            name of the role |default| :data:`"new role"`
894
        permissions : Optional[:class:`str`]
895
            bitwise value of the enabled/disabled
896
            permissions, set to @everyone permissions
897
            by default |default| :data:`None`
898
        color : Optional[:class:`int`]
899
            RGB color value |default| :data:`0`
900
        hoist : Optional[:class:`bool`]
901
            whether the role should be displayed
902
            separately in the sidebar |default| :data:`False`
903
        icon : Optional[:class:`str`]
904
            the role's icon image (if the guild has
905
            the ``ROLE_ICONS`` feature) |default| :data:`None`
906
        unicode_emoji : Optional[:class:`str`]
907
            the role's unicode emoji as a standard emoji (if the guild
908
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
909
        mentionable : Optional[:class:`bool`]
910
            whether the role should be mentionable |default| :data:`False`
911
912
        Returns
913
        -------
914
        :class:`~pincer.objects.guild.role.Role`
915
            The new role object.
916
        """
917
        ...
918
919
    async def create_role(self, reason: Optional[str] = None, **kwargs) -> Role:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
920
        return Role.from_dict(
921
            await self._http.post(
922
                f"guilds/{self.id}/roles",
923
                data=kwargs,
924
                headers={"X-Audit-Log-Reason": reason},
925
            )
926
        )
927
928
    async def edit_role_position(
929
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
930
        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...
931
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
932
        position: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
933
    ) -> AsyncGenerator[Role, None]:
934
        """|coro|
935
        Edits the position of a role.
936
937
        Parameters
938
        ----------
939
        id : :class:`~pincer.utils.snowflake.Snowflake`
940
            The role ID
941
        reason : Optional[:class:`str`]
942
            Reason for editing the role position. |default| :data:`None`
943
        position : Optional[:class:`int`]
944
            Sorting position of the role |default| :data:`None`
945
946
        Yields
947
        -------
948
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
949
            An async generator of all the guild's role objects.
950
        """
951
        data = await self._http.patch(
952
            f"guilds/{self.id}/roles",
953
            data={"id": id, "position": position},
954
            headers={"X-Audit-Log-Reason": reason},
955
        )
956
        for role_data in data:
957
            yield Role.from_dict(role_data)
958
959
    @overload
960
    async def edit_role(
961
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
962
        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...
963
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
964
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
965
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
966
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
967
        color: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
968
        hoist: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
969
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
970
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
971
        mentionable: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
972
    ) -> Role:
973
        """|coro|
974
        Edits a role.
975
        Requires the ``MANAGE_ROLES`` permission.
976
977
        Parameters
978
        ----------
979
        id : :class:`~pincer.utils.snowflake.Snowflake`
980
            The role ID
981
        reason : Optional[:class:`str`]
982
            Reason for editing the role |default| :data:`None`
983
        name : Optional[:class:`str`]
984
            Name of the role |default| :data:`None`
985
        permissions : Optional[:class:`str`]
986
            Bitwise value of the enabled/disabled
987
            permissions |default| :data:`None`
988
        color : Optional[:class:`int`]
989
            RGB color value |default| :data:`None`
990
        hoist : Optional[:class:`bool`]
991
            Whether the role should be displayed
992
            separately in the sidebar |default| :data:`None`
993
        icon : Optional[:class:`str`]
994
            The role's icon image (if the guild has
995
            the ``ROLE_ICONS`` feature) |default| :data:`None`
996
        unicode_emoji : Optional[:class:`str`]
997
            The role's unicode emoji as a standard emoji (if the guild
998
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
999
        mentionable : Optional[:class:`bool`]
1000
            Whether the role should be mentionable |default| :data:`None`
1001
1002
        Returns
1003
        -------
1004
        :class:`~pincer.objects.guild.role.Role`
1005
            The edited role object.
1006
        """
1007
        ...
1008
1009
    async def edit_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
1010
        self, id: Snowflake, reason: Optional[str] = None, **kwargs
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1011
    ) -> Role:
1012
        return Role.from_dict(
1013
            await self._http.patch(
1014
                f"guilds/{self.id}/roles/{id}",
1015
                data=kwargs,
1016
                headers={"X-Audit-Log-Reason": reason},
1017
            )
1018
        )
1019
1020
    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...
1021
        """|coro|
1022
        Deletes a role.
1023
        Requires the `MANAGE_ROLES` permission.
1024
1025
        Parameters
1026
        ----------
1027
        id : :class:`~pincer.utils.snowflake.Snowflake`
1028
            The role ID
1029
        reason : Optional[:class:`str`]
1030
            The reason for deleting the role |default| :data:`None`
1031
        """
1032
        await self._http.delete(
1033
            f"guilds/{self.id}/roles/{id}",
1034
            headers={"X-Audit-Log-Reason": reason},
1035
        )
1036
1037
    async def get_bans(self) -> AsyncGenerator[Ban, None]:
1038
        """|coro|
1039
        Fetches all the bans in the guild.
1040
1041
        Yields
1042
        -------
1043
        AsyncGenerator[:class:`~pincer.objects.guild.ban.Ban`, :data:`None`]
1044
            An async generator of Ban objects.
1045
        """
1046
        data = await self._http.get(f"guilds/{self.id}/bans")
1047
        for ban_data in data:
1048
            yield Ban.from_dict(ban_data)
1049
1050
    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...
1051
        """|coro|
1052
        Fetches a ban from the guild.
1053
1054
        Parameters
1055
        ----------
1056
        id : :class:`~pincer.utils.snowflake.Snowflake`
1057
            The user ID
1058
1059
        Returns
1060
        -------
1061
        :class:`~pincer.objects.guild.ban.Ban`
1062
            The Ban object.
1063
        """
1064
        return Ban.from_dict(
1065
            await self._http.get(f"guilds/{self.id}/bans/{id}")
1066
        )
1067
1068
    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...
1069
        """|coro|
1070
        Unbans a user from the guild.
1071
1072
        Parameters
1073
        ----------
1074
        id : :class:`~pincer.utils.snowflake.Snowflake`
1075
            The user ID
1076
        reason : Optional[:class:`str`]
1077
            The reason for unbanning the user |default| :data:`None`
1078
        """
1079
        await self._http.delete(
1080
            f"guilds/{self.id}/bans/{id}",
1081
            headers={"X-Audit-Log-Reason": reason},
1082
        )
1083
1084
    @overload
1085
    async def edit(
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (20/15).
Loading history...
1086
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1087
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1088
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1089
        region: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1090
        verification_level: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1091
        default_message_notifications: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1092
        explicit_content_filter: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1093
        afk_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1094
        afk_timeout: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1095
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1096
        owner_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1097
        splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1098
        discovery_splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1099
        banner: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1100
        system_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1101
        system_channel_flags: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1102
        rules_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1103
        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...
1104
        preferred_locale: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1105
        features: Optional[List[GuildFeature]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1106
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1107
    ) -> Guild:
1108
        """|coro|
1109
        Modifies the guild
1110
1111
        Parameters
1112
        ----------
1113
        name : Optional[:class:`str`]
1114
            Guild name |default| :data:`None`
1115
        region : Optional[:class:`str`]
1116
            Guild voice region ID |default| :data:`None`
1117
        verification_level : Optional[:class:`int`]
1118
            Verification level |default| :data:`None`
1119
        default_message_notifications : Optional[:class:`int`]
1120
            Default message notification level |default| :data:`None`
1121
        explicit_content_filter : Optional[:class:`int`]
1122
            Explicit content filter level |default| :data:`None`
1123
        afk_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1124
            ID for AFK channel |default| :data:`None`
1125
        afk_timeout : Optional[:class:`int`]
1126
            AFK timeout in seconds |default| :data:`None`
1127
        icon : Optional[:class:`str`]
1128
            base64 1024x1024 png/jpeg/gif image for the guild icon
1129
            (can be animated gif when the server
1130
            has the `ANIMATED_ICON` feature) |default| :data:`None`
1131
        owner_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1132
            User ID to transfer guild ownership to (must be owner) |default| :data:`None`
1133
        splash : Optional[:class:`str`]
1134
            base64 16:9 png/jpeg image for the guild splash (when the
1135
            server has the `INVITE_SPLASH` feature) |default| :data:`None`
1136
        discovery_splash : Optional[:class:`str`]
1137
            base64 16:9 png/jpeg image for the guild discovery splash
1138
            (when the server has the `DISCOVERABLE` feature) |default| :data:`None`
1139
        banner : Optional[:class:`str`]
1140
            base64 16:9 png/jpeg image for the guild banner (when the
1141
            server has the `BANNER` feature) |default| :data:`None`
1142
        system_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1143
            The ID of the channel where guild notices such as welcome
1144
            messages and boost events are posted |default| :data:`None`
1145
        system_channel_flags : Optional[:class:`int`]
1146
            System channel flags |default| :data:`None`
1147
        rules_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1148
            The ID of the channel where Community guilds display rules
1149
            and/or guidelines |default| :data:`None`
1150
        public_updates_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1151
            The ID of the channel where admins and moderators of
1152
            Community guilds receive notices from Discord |default| :data:`None`
1153
        preferred_locale : Optional[:class:`str`]
1154
            The preferred locale of a Community guild used in server
1155
            discovery and notices from Discord; defaults to "en-US" |default| :data:`None`
1156
        features : Optional[List[:class:`GuildFeature`]]
1157
            Enabled guild features |default| :data:`None`
1158
        description : Optional[:class:`str`]
1159
            The description for the guild, if the guild is discoverable |default| :data:`None`
1160
1161
        Returns
1162
        -------
1163
        :class:`~pincer.objects.guild.Guild`
1164
            The modified guild object.
1165
        """
1166
        ...
1167
1168
    async def edit(self, **kwargs) -> Guild:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
1169
        g = await self._http.patch(f"guilds/{self.id}", data=kwargs)
1170
        return Guild.from_dict(g)
1171
1172
    async def preview(self) -> GuildPreview:
1173
        """|coro|
1174
        Previews the guild.
1175
1176
        Returns
1177
        -------
1178
        :class:`~pincer.objects.guild.guild.GuildPreview`
1179
            The guild preview object.
1180
        """
1181
        data = await self._http.get(f"guilds/{self.id}/preview")
1182
        return GuildPreview.from_dict(data)
1183
1184
    async def delete(self):
1185
        """|coro|
1186
        Deletes the guild. Returns `204 No Content` on success.
1187
        """
1188
        await self._http.delete(f"guilds/{self.id}")
1189
1190
    async def prune_count(
1191
        self, days: Optional[int] = 7, include_roles: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1192
    ) -> int:
1193
        """|coro|
1194
        Returns the number of members that
1195
        would be removed in a prune operation.
1196
        Requires the ``KICK_MEMBERS`` permission.
1197
1198
        Parameters
1199
        ----------
1200
        days : Optional[:class:`int`]
1201
            Number of days to count prune for (1-30) |default| :data:`7`
1202
        include_roles : Optional[:class:`str`]
1203
            Comma-delimited array of Snowflakes;
1204
            role(s) to include |default| :data:`None`
1205
1206
        Returns
1207
        -------
1208
        :class:`int`
1209
            The number of members that would be removed.
1210
        """
1211
        return await self._http.get(
1212
            f"guilds/{self.id}/prune",
1213
            params={"days": days, "include_roles": include_roles},
1214
        )["pruned"]
1215
1216
    async def prune(
1217
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1218
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1219
        compute_prune_days: Optional[bool] = True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1220
        include_roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1221
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1222
    ) -> int:
1223
        """|coro|
1224
        Prunes members from the guild. Requires the ``KICK_MEMBERS`` permission.
1225
1226
        Parameters
1227
1228
        Parameters
1229
        ----------
1230
        days : Optional[:class:`int`]
1231
            Number of days to prune (1-30) |default| :data:`7`
1232
        compute_prune_days : Optional[:class:`bool`]
1233
            Whether ``pruned`` is returned, discouraged for large guilds
1234
            |default| :data:`True`
1235
        include_roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1236
            role(s) to include |default| :data:`None`
1237
        reason : Optional[:class:`str`]
1238
            Reason for the prune |default| :data:`None`
1239
1240
        Returns
1241
        -------
1242
        :class:`int`
1243
            The number of members that were removed.
1244
        """
1245
        return await self._http.post(
1246
            f"guilds/{self.id}/prune",
1247
            data={
1248
                "days": days,
1249
                "compute_prune_days": compute_prune_days,
1250
                "include_roles": include_roles,
1251
            },
1252
            headers={"X-Audit-Log-Reason": reason},
1253
        )["pruned"]
1254
1255
    async def get_voice_regions(self) -> AsyncGenerator[VoiceRegion, None]:
1256
        """|coro|
1257
        Returns an async generator of voice regions.
1258
1259
        Yields
1260
        -------
1261
        AsyncGenerator[:class:`~pincer.objects.voice.VoiceRegion`, :data:`None`]
1262
            An async generator of voice regions.
1263
        """
1264
        data = await self._http.get(f"guilds/{self.id}/regions")
1265
        for voice_region_data in data:
1266
            yield VoiceRegion.from_dict(voice_region_data)
1267
1268
    async def get_invites(self) -> AsyncGenerator[Invite, None]:
1269
        """|coro|
1270
        Returns an async generator of invites for the guild.
1271
        Requires the ``MANAGE_GUILD`` permission.
1272
1273
        Yields
1274
        -------
1275
        AsyncGenerator[:class:`~pincer.objects.invite.Invite`, :data:`None`]
1276
            An async generator of invites.
1277
        """
1278
        data = await self._http.get(f"guilds/{self.id}/invites")
1279
        for invite_data in data:
1280
            yield Invite.from_dict(invite_data)
1281
1282
    async def get_invite(self, code: str) -> Invite:
1283
        """|coro|
1284
        Returns an invite object for an invite code.
1285
1286
        Parameters
1287
        ----------
1288
        code : :class:`str`
1289
            The invite code to get the invite for.
1290
1291
        Returns
1292
        -------
1293
        :class:`~pincer.objects.invite.Invite`
1294
            The invite object.
1295
        """
1296
        data = await self._http.get(f"invite/{code}")
1297
        return Invite.from_dict(data)
1298
1299
    async def get_integrations(self) -> AsyncIterator[Integration]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
1300
        """|coro|
1301
        Returns an async generator of integrations for the guild.
1302
        Requires the ``MANAGE_GUILD`` permission.
1303
1304
        Yields
1305
        -------
1306
        AsyncGenerator[:class:`~pincer.objects.integration.Integration`, :data:`None`]
1307
            An async generator of integrations.
1308
        """
1309
        data = await self._http.get(f"guilds/{self.id}/integrations")
1310
        for integration_data in data:
1311
            yield Integration.from_dict(integration_data)
1312
1313
    async def delete_integration(
1314
        self, integration: Integration, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1315
    ):
1316
        """|coro|
1317
        Deletes an integration.
1318
        Requires the ``MANAGE_GUILD`` permission.
1319
1320
        Parameters
1321
        ----------
1322
        integration : :class:`~pincer.objects.integration.Integration`
1323
            The integration to delete.
1324
        reason : Optional[:class:`str`]
1325
            Reason for the deletion |default| :data:`None`
1326
        """
1327
        await self._http.delete(
1328
            f"guilds/{self.id}/integrations/{integration.id}",
1329
            headers={"X-Audit-Log-Reason": reason},
1330
        )
1331
1332
    async def delete_invite(self, code: str):
1333
        """|coro|
1334
        Deletes an invite.
1335
        Requires the ``MANAGE_GUILD`` permission.
1336
        """
1337
        await self._http.delete(f"guilds/{self.id}/invites/{code}")
1338
1339
    async def get_widget_settings(self) -> GuildWidget:
1340
        """|coro|
1341
        Returns the guild widget settings.
1342
        Requires the ``MANAGE_GUILD`` permission.
1343
1344
        Returns
1345
        -------
1346
        :class:`~pincer.objects.guild.widget.GuildWidget`
1347
            The guild widget settings.
1348
        """
1349
        return GuildWidget.from_dict(
1350
            await self._http.get(f"guilds/{self.id}/widget")
1351
        )
1352
1353
    async def modify_widget(
1354
        self, reason: Optional[str] = None, **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1355
    ) -> GuildWidget:
1356
        """|coro|
1357
        Modifies the guild widget for the guild.
1358
        Requires the ``MANAGE_GUILD`` permission.
1359
1360
        Parameters
1361
        ----------
1362
        reason : Optional[:class:`str`]
1363
            Reason for the modification |default| :data:`None`
1364
        \\*\\*kwargs
1365
            The widget settings to modify
1366
1367
        Returns
1368
        -------
1369
        :class:`~pincer.objects.guild.widget.GuildWidget`
1370
            The updated GuildWidget object
1371
        """
1372
        data = await self._http.patch(
1373
            f"guilds/{self.id}/widget",
1374
            data=kwargs,
1375
            headers={"X-Audit-Log-Reason": reason},
1376
        )
1377
        return GuildWidget.from_dict(data)
1378
1379
    async def get_widget(self) -> Dict[str, JSONSerializable]:
1380
        """|coro|
1381
        Returns the widget for the guild
1382
        """
1383
        return await self._http.get(f"guilds/{self.id}/widget.json")
1384
1385
    @property
1386
    async def vanity_url(self) -> Invite:
1387
        """|coro|
1388
        Returns the Vanity URL for the guild.
1389
        Requires the ``MANAGE_GUILD`` permission.
1390
        ``code`` will be null if a vanity URL has not been set.
1391
1392
        Returns
1393
        -------
1394
        :class:`~pincer.objects.guild.invite.Invite`
1395
            The vanity url for the guild.
1396
        """
1397
        data = await self._http.get(f"guilds/{self.id}/vanity-url")
1398
        return Invite.from_dict(data)
1399
1400
    async def get_widget_image(
1401
        self, style: Optional[str] = "shield"
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1402
    ) -> 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...
1403
        """|coro|
1404
        Returns a PNG image widget for the guild.
1405
        Requires no permissions or authentication.
1406
1407
        Widget Style Options
1408
        -------------------
1409
        * [``shield``](https://discord.com/api/guilds/81384788765712384/widget.png?style=shield)
1410
          shield style widget with Discord icon and guild members online count
1411
        * [``banner1``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner1)
1412
          large image with guild icon, name and online count.
1413
          "POWERED BY DISCORD" as the footer of the widget
1414
        * [``banner2``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner2)
1415
          smaller widget style with guild icon, name and online count.
1416
          Split on the right with Discord logo
1417
        * [``banner3``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner3)
1418
          large image with guild icon, name and online count.
1419
          In the footer, Discord logo on the
1420
          left and "Chat Now" on the right
1421
        * [``banner4``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner4)
1422
          large Discord logo at the top of the widget.
1423
          Guild icon, name and online count in the middle portion
1424
          of the widget and a "JOIN MY SERVER" button at the bottom
1425
1426
        Parameters
1427
        ----------
1428
        style : Optional[:class:`str`]
1429
            Style of the widget image returned |default| :data:`"shield"`
1430
1431
        Returns
1432
        -------
1433
        :class:`str`
1434
            A PNG image of the guild widget.
1435
        """
1436
        return await self._http.get(f"guilds/{self.id}/widget.png?{style=!s}")
1437
1438
    async def get_welcome_screen(self) -> WelcomeScreen:
1439
        """Returns the welcome screen for the guild.
1440
1441
        Returns
1442
        -------
1443
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1444
            The welcome screen for the guild.
1445
        """
1446
        data = await self._http.get(f"guilds/{self.id}/welcome-screen")
1447
        return WelcomeScreen.from_dict(data)
1448
1449
    async def modify_welcome_screen(
1450
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1451
        enabled: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1452
        welcome_channels: Optional[List[WelcomeScreenChannel]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1453
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1454
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1455
    ) -> WelcomeScreen:
1456
        """|coro|
1457
        Modifies the guild's Welcome Screen.
1458
        Requires the ``MANAGE_GUILD`` permission.
1459
1460
        Parameters
1461
        ----------
1462
        enabled : Optional[:class:`bool`]
1463
            Whether the welcome screen is enabled |default| :data:`None`
1464
        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...
1465
            Channels linked in the welcome screen and
1466
            their display options |default| :data:`None`
1467
        description : Optional[:class:`str`]
1468
            The server description to show
1469
            in the welcome screen |default| :data:`None`
1470
        reason : Optional[:class:`str`]
1471
            Reason for the modification |default| :data:`None`
1472
1473
        Returns
1474
        -------
1475
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1476
            The updated WelcomeScreen object
1477
        """
1478
        data = await self._http.patch(
1479
            f"guilds/{self.id}/welcome-screen",
1480
            data={
1481
                "enabled": enabled,
1482
                "welcome_channels": welcome_channels,
1483
                "description": description,
1484
            },
1485
            headers={"X-Audit-Log-Reason": reason},
1486
        )
1487
        return WelcomeScreen.from_dict(data)
1488
1489
    async def modify_current_user_voice_state(
1490
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1491
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1492
        suppress: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1493
        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...
1494
    ):
1495
        """|coro|
1496
        Updates the current user's voice state.
1497
1498
        There are currently several caveats for this endpoint:
1499
        * ``channel_id`` must currently point to a stage channel
1500
        * current user must already have joined ``channel_id``
1501
        * You must have the ``MUTE_MEMBERS`` permission to
1502
          unsuppress yourself. You can always suppress yourself.
1503
        * You must have the ``REQUEST_TO_SPEAK`` permission to request
1504
          to speak. You can always clear your own request to speak.
1505
        * You are able to set ``request_to_speak_timestamp`` to any
1506
          present or future time.
1507
1508
        Parameters
1509
        ----------
1510
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1511
            The ID of the channel the user is currently in
1512
        suppress : Optional[:class:`bool`]
1513
            Toggles the user's suppress state |default| :data:`None`
1514
        request_to_speak_timestamp : Optional[:class:`~pincer.utils.timestamp.Timestamp`]
1515
            Sets the user's request to speak
1516
        """
1517
        await self._http.patch(
1518
            f"guilds/{self.id}/voice-states/@me",
1519
            data={
1520
                "channel_id": channel_id,
1521
                "suppress": suppress,
1522
                "request_to_speak_timestamp": request_to_speak_timestamp,
1523
            },
1524
        )
1525
1526
    async def modify_user_voice_state(
1527
        self, user: User, channel_id: Snowflake, suppress: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1528
    ):
1529
        """|coro|
1530
        Updates another user's voice state.
1531
1532
        There are currently several caveats for this endpoint:
1533
        * ``channel_id`` must currently point to a stage channel
1534
        * User must already have joined ``channel_id``
1535
        * You must have the ``MUTE_MEMBERS`` permission.
1536
          (Since suppression is the only thing that is available currently.)
1537
        * When unsuppressed, non-bot users will have their
1538
          ``request_to_speak_timestamp`` set to the current time.
1539
          Bot users will not.
1540
        * When suppressed, the user will have their
1541
          ``request_to_speak_timestamp`` removed.
1542
1543
        Parameters
1544
        ----------
1545
        user : :class:`~pincer.objects.guild.member.Member`
1546
            The user to update
1547
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1548
            The ID of the channel the user is currently in
1549
        suppress : Optional[:class:`bool`]
1550
            Toggles the user's suppress state |default| :data:`None`
1551
        """
1552
        await self._http.patch(
1553
            f"guilds/{self.id}/voice-states/{user.id}",
1554
            data={"channel_id": channel_id, "suppress": suppress},
1555
        )
1556
1557
    async def get_audit_log(self) -> AuditLog:
1558
        """|coro|
1559
        Returns an audit log object for the guild.
1560
        Requires the ``VIEW_AUDIT_LOG`` permission.
1561
1562
        Returns
1563
        -------
1564
        :class:`~pincer.objects.guild.audit_log.AuditLog`
1565
            The audit log object for the guild.
1566
        """
1567
        return AuditLog.from_dict(
1568
            await self._http.get(f"guilds/{self.id}/audit-logs")
1569
        )
1570
1571
    async def get_emojis(self) -> AsyncGenerator[Emoji, None]:
1572
        """|coro|
1573
        Returns an async generator of the emojis in the guild.
1574
1575
        Yields
1576
        ------
1577
        :class:`~pincer.objects.guild.emoji.Emoji`
1578
            The emoji object.
1579
        """
1580
        data = await self._http.get(f"guilds/{self.id}/emojis")
1581
        for emoji_data in data:
1582
            yield Emoji.from_dict(emoji_data)
1583
1584
    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...
1585
        """|coro|
1586
        Returns an emoji object for the given ID.
1587
1588
        Parameters
1589
        ----------
1590
        id : :class:`~pincer.utils.snowflake.Snowflake`
1591
            The ID of the emoji
1592
1593
        Returns
1594
        -------
1595
        :class:`~pincer.objects.guild.emoji.Emoji`
1596
            The emoji object.
1597
        """
1598
        return Emoji.from_dict(
1599
            await self._http.get(f"guilds/{self.id}/emojis/{id}")
1600
        )
1601
1602
    async def create_emoji(
1603
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1604
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1605
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1606
        image: File,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1607
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1608
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1609
    ) -> Emoji:
1610
        """|coro|
1611
        Creates a new emoji for the guild.
1612
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1613
1614
        Emojis and animated emojis have a maximum file size of 256kb.
1615
        Attempting to upload an emoji larger than this limit will fail.
1616
1617
        Parameters
1618
        ----------
1619
        name : :class:`str`
1620
            Name of the emoji
1621
        image : :class:`~pincer.objects.message.file.File`
1622
            The File for the 128x128 emoji image data
1623
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1624
            Roles allowed to use this emoji |default| :data:`[]`
1625
        reason : Optional[:class:`str`]
1626
            The reason for creating the emoji |default| :data:`None`
1627
1628
        Returns
1629
        -------
1630
        :class:`~pincer.objects.guild.emoji.Emoji`
1631
            The newly created emoji object.
1632
        """
1633
        roles = [] if roles is None else roles
1634
1635
        data = await self._http.post(
1636
            f"guilds/{self.id}/emojis",
1637
            data={"name": name, "image": image.uri, "roles": roles},
1638
            headers={"X-Audit-Log-Reason": reason},
1639
        )
1640
        return Emoji.from_dict(data)
1641
1642
    async def edit_emoji(
1643
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1644
        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...
1645
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1646
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1647
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1648
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1649
    ) -> Emoji:
1650
        """|coro|
1651
        Modifies the given emoji.
1652
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1653
1654
        Parameters
1655
        ----------
1656
        id : :class:`~pincer.utils.snowflake.Snowflake`
1657
            The ID of the emoji
1658
        name : Optional[:class:`str`]
1659
            Name of the emoji |default| :data:`None`
1660
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1661
            Roles allowed to use this emoji |default| :data:`None`
1662
        reason : Optional[:class:`str`]
1663
            The reason for editing the emoji |default| :data:`None`
1664
1665
        Returns
1666
        -------
1667
        :class:`~pincer.objects.guild.emoji.Emoji`
1668
            The modified emoji object.
1669
        """
1670
        data = await self._http.patch(
1671
            f"guilds/{self.id}/emojis/{id}",
1672
            data={"name": name, "roles": roles},
1673
            headers={"X-Audit-Log-Reason": reason},
1674
        )
1675
        return Emoji.from_dict(data)
1676
1677
    async def delete_emoji(
1678
        self, id: Snowflake, *, reason: Optional[str] = None
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1679
    ):
1680
        """|coro|
1681
        Deletes the given emoji.
1682
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1683
1684
        Parameters
1685
        ----------
1686
        id : :class:`~pincer.utils.snowflake.Snowflake`
1687
            The ID of the emoji
1688
        reason : Optional[:class:`str`]
1689
            The reason for deleting the emoji |default| :data:`None`
1690
        """
1691
        await self._http.delete(
1692
            f"guilds/{self.id}/emojis/{id}",
1693
            headers={"X-Audit-Log-Reason": reason},
1694
        )
1695
1696
    async def get_templates(self) -> AsyncIterator[GuildTemplate]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
1697
        """|coro|
1698
        Returns an async generator of the guild templates.
1699
1700
        Yields
1701
        -------
1702
        AsyncGenerator[:class:`~pincer.objects.guild.template.GuildTemplate`, :data:`None`]
1703
            The guild template object.
1704
        """
1705
        data = await self._http.get(f"guilds/{self.id}/templates")
1706
        for template_data in data:
1707
            yield GuildTemplate.from_dict(template_data)
1708
1709
    async def create_template(
1710
        self, name: str, description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1711
    ) -> GuildTemplate:
1712
        """|coro|
1713
        Creates a new template for the guild.
1714
        Requires the ``MANAGE_GUILD`` permission.
1715
1716
        Parameters
1717
        ----------
1718
        name : :class:`str`
1719
            Name of the template (1-100 characters)
1720
        description : Optional[:class:`str`]
1721
            Description of the template
1722
            (0-120 characters) |default| :data:`None`
1723
        Returns
1724
        -------
1725
        :class:`~pincer.objects.guild.template.GuildTemplate`
1726
            The newly created template object.
1727
        """
1728
        data = await self._http.post(
1729
            f"guilds/{self.id}/templates",
1730
            data={"name": name, "description": description},
1731
        )
1732
        return GuildTemplate.from_dict(data)
1733
1734
    async def sync_template(self, template: GuildTemplate) -> GuildTemplate:
1735
        """|coro|
1736
        Syncs the given template.
1737
        Requires the ``MANAGE_GUILD`` permission.
1738
1739
        Parameters
1740
        ----------
1741
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1742
            The template to sync
1743
1744
        Returns
1745
        -------
1746
        :class:`~pincer.objects.guild.template.GuildTemplate`
1747
            The synced template object.
1748
        """
1749
        data = await self._http.put(
1750
            f"guilds/{self.id}/templates/{template.code}"
1751
        )
1752
        return GuildTemplate.from_dict(data)
1753
1754
    async def edit_template(
1755
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1756
        template: GuildTemplate,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1757
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1758
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1759
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1760
    ) -> GuildTemplate:
1761
        """|coro|
1762
        Modifies the template's metadata.
1763
        Requires the ``MANAGE_GUILD`` permission.
1764
1765
        Parameters
1766
        ----------
1767
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1768
            The template to edit
1769
        name : Optional[:class:`str`]
1770
            Name of the template (1-100 characters)
1771
            |default| :data:`None`
1772
        description : Optional[:class:`str`]
1773
            Description of the template (0-120 characters)
1774
            |default| :data:`None`
1775
1776
        Returns
1777
        -------
1778
        :class:`~pincer.objects.guild.template.GuildTemplate`
1779
            The edited template object.
1780
        """
1781
        data = await self._http.patch(
1782
            f"guilds/{self.id}/templates/{template.code}",
1783
            data={"name": name, "description": description},
1784
        )
1785
        return GuildTemplate.from_dict(data)
1786
1787
    async def delete_template(self, template: GuildTemplate) -> GuildTemplate:
1788
        """|coro|
1789
        Deletes the given template.
1790
        Requires the ``MANAGE_GUILD`` permission.
1791
1792
        Parameters
1793
        ----------
1794
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1795
            The template to delete
1796
1797
        Returns
1798
        -------
1799
        :class:`~pincer.objects.guild.template.GuildTemplate`
1800
            The deleted template object.
1801
        """
1802
        data = await self._http.delete(
1803
            f"guilds/{self.id}/templates/{template.code}"
1804
        )
1805
        return GuildTemplate.from_dict(data)
1806
1807
    async def list_stickers(self) -> AsyncIterator[Sticker]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
1808
        """|coro|
1809
        Yields sticker objects for the current guild.
1810
        Includes ``user`` fields if the bot has the
1811
        ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1812
1813
        Yields
1814
        ------
1815
        :class:`~pincer.objects.message.sticker.Sticker`
1816
            a sticker for the current guild
1817
        """
1818
1819
        for sticker in await self._http.get(f"guild/{self.id}/stickers"):
1820
            yield Sticker.from_dict(sticker)
1821
1822
    async def get_sticker(self, _id: Snowflake) -> Sticker:
1823
        """|coro|
1824
        Returns a sticker object for the current guild and sticker IDs.
1825
        Includes the ``user`` field if the bot has the
1826
        ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1827
1828
        Parameters
1829
        ----------
1830
        _id : int
1831
            id of the sticker
1832
1833
        Returns
1834
        -------
1835
        :class:`~pincer.objects.message.sticker.Sticker`
1836
            the sticker requested
1837
        """
1838
        sticker = await self._http.get(f"guilds/{self.id}/stickers/{_id}")
1839
        return Sticker.from_dict(sticker)
1840
1841
    async def create_sticker(
0 ignored issues
show
best-practice introduced by
Too many arguments (6/5)
Loading history...
1842
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1843
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1844
        tags: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1845
        description: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1846
        file: File,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1847
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1848
    ) -> Sticker:
1849
        """|coro|
1850
        Create a new sticker for the guild.
1851
        Requires the ``MANAGE_EMOJIS_AND_STICKERS permission``.
1852
1853
        Parameters
1854
        ----------
1855
        name : str
1856
            name of the sticker (2-30 characters)
1857
        tags : str
1858
            autocomplete/suggestion tags for the sticker (max 200 characters)
1859
        file : :class:`~pincer.objects.message.file.File`
1860
            the sticker file to upload, must be a PNG, APNG, or Lottie JSON file, max 500 KB
1861
        description : str
1862
            description of the sticker (empty or 2-100 characters) |default| :data:`""`
1863
        reason : Optional[:class:`str`] |default| :data:`None`
1864
            reason for creating the sticker
1865
1866
        Returns
1867
        -------
1868
        :class:`~pincer.objects.message.sticker.Sticker`
1869
            the newly created sticker
1870
        """  # noqa: E501
1871
1872
        form = FormData()
1873
        form.add_field("name", name)
1874
        form.add_field("tags", tags)
1875
        form.add_field("description", description)
1876
        form.add_field("file", file.content, content_type=file.content_type)
1877
1878
        payload = form()
1879
1880
        sticker = await self._http.post(
1881
            f"guilds/{self.id}/stickers",
1882
            data=payload,
1883
            headers={"X-Audit-Log-Reason": reason},
1884
            content_type=payload.content_type,
1885
        )
1886
1887
        return Sticker.from_dict(sticker)
1888
1889
    async def delete_sticker(self, _id: Snowflake):
1890
        """|coro|
1891
        Delete the given sticker.
1892
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1893
1894
        Parameters
1895
        ----------
1896
        _id: Snowflake
1897
            id of the sticker
1898
        """
1899
        await self._http.delete(f"guilds/{self.id}/stickers/{_id}")
1900
1901
    async def get_webhooks(self) -> AsyncGenerator[Webhook, None]:
1902
        """|coro|
1903
        Returns an async generator of the guild webhooks.
1904
1905
        Yields
1906
        -------
1907
        AsyncGenerator[:class:`~pincer.objects.guild.webhook.Webhook`, None]
1908
            The guild webhook object.
1909
        """
1910
        data = await self._http.get(f"guilds/{self.id}/webhooks")
1911
        for webhook_data in data:
1912
            yield Webhook.from_dict(webhook_data)
1913
1914
    @classmethod
1915
    def from_dict(cls, data) -> Guild:
1916
        """
1917
        Parameters
1918
        ----------
1919
        data : :class:`Dict`
1920
            Guild data received from the discord API.
1921
        Returns
1922
        -------
1923
        :class:`~pincer.objects.guild.guild.Guild`
1924
            The new guild object.
1925
        Raises
1926
        ------
1927
        :class:`~pincer.exceptions.UnavailableGuildError`
1928
            The guild is unavailable due to a discord outage.
1929
        """
1930
        if data.get("unavailable", False):
1931
            raise UnavailableGuildError(
1932
                f"Guild \"{data['id']}\" is unavailable due to a discord"
1933
                " outage."
1934
            )
1935
1936
        return super().from_dict(data)
1937
1938
1939
@dataclass(repr=False)
1940
class UnavailableGuild(APIObject):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
1941
    id: Snowflake
1942
    unavailable: bool = True
1943