Passed
Branch main (c248a1)
by Yohann
01:42
created

Guild.modify_current_user_voice_state()   A

Complexity

Conditions 1

Size

Total Lines 34
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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

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

Loading history...
1080
        """|coro|
1081
        Returns a PNG image widget for the guild.
1082
        Requires no permissions or authentication.
1083
1084
        Widget Style Options
1085
        -------------------
1086
        * [``shield``](https://discord.com/api/guilds/81384788765712384/widget.png?style=shield)
1087
          shield style widget with Discord icon and guild members online count
1088
        * [``banner1``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner1)
1089
          large image with guild icon, name and online count.
1090
          "POWERED BY DISCORD" as the footer of the widget
1091
        * [``banner2``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner2)
1092
          smaller widget style with guild icon, name and online count.
1093
          Split on the right with Discord logo
1094
        * [``banner3``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner3)
1095
          large image with guild icon, name and online count.
1096
          In the footer, Discord logo on the
1097
          left and "Chat Now" on the right
1098
        * [``banner4``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner4)
1099
          large Discord logo at the top of the widget.
1100
          Guild icon, name and online count in the middle portion
1101
          of the widget and a "JOIN MY SERVER" button at the bottom
1102
1103
        Parameters
1104
        ----------
1105
        style : Optional[:class:`str`]
1106
            Style of the widget image returned |default| :data:`"shield"`
1107
1108
        Returns
1109
        -------
1110
        :class:`str`
1111
            A PNG image of the guild widget.
1112
        """
1113
        return await self._http.get(f"guilds/{self.id}/widget.png?{style=!s}")
1114
1115
    async def get_welcome_screen(self) -> WelcomeScreen:
1116
        """Returns the welcome screen for the guild.
1117
1118
        Returns
1119
        -------
1120
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1121
            The welcome screen for the guild.
1122
        """
1123
        data = await self._http.get(f"guilds/{self.id}/welcome-screen")
1124
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1125
1126
    async def modify_welcome_screen(
1127
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1128
        enabled: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1129
        welcome_channels: Optional[List[WelcomeScreenChannel]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1130
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1131
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1132
    ) -> WelcomeScreen:
1133
        """|coro|
1134
        Modifies the guild's Welcome Screen.
1135
        Requires the ``MANAGE_GUILD`` permission.
1136
1137
        Parameters
1138
        ----------
1139
        enabled : Optional[:class:`bool`]
1140
            Whether the welcome screen is enabled |default| :data:`None`
1141
        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...
1142
            Channels linked in the welcome screen and
1143
            their display options |default| :data:`None`
1144
        description : Optional[:class:`str`]
1145
            The server description to show
1146
            in the welcome screen |default| :data:`None`
1147
        reason : Optional[:class:`str`]
1148
            Reason for the modification |default| :data:`None`
1149
1150
        Returns
1151
        -------
1152
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1153
            The updated WelcomeScreen object
1154
        """
1155
        data = await self._http.patch(
1156
            f"guilds/{self.id}/welcome-screen",
1157
            data={
1158
                "enabled": enabled,
1159
                "welcome_channels": welcome_channels,
1160
                "description": description
1161
            },
1162
            headers=remove_none({"X-Audit-Log-Reason": reason})
1163
        )
1164
        return WelcomeScreen.from_dict(construct_client_dict(self._client, data))
1165
1166
    async def modify_current_user_voice_state(
1167
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1168
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1169
        suppress: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1170
        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...
1171
    ):
1172
        """|coro|
1173
        Updates the current user's voice state.
1174
1175
        There are currently several caveats for this endpoint:
1176
        * ``channel_id`` must currently point to a stage channel
1177
        * current user must already have joined ``channel_id``
1178
        * You must have the ``MUTE_MEMBERS`` permission to
1179
          unsuppress yourself. You can always suppress yourself.
1180
        * You must have the ``REQUEST_TO_SPEAK`` permission to request
1181
          to speak. You can always clear your own request to speak.
1182
        * You are able to set ``request_to_speak_timestamp`` to any
1183
          present or future time.
1184
1185
        Parameters
1186
        ----------
1187
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1188
            The ID of the channel the user is currently in
1189
        suppress : Optional[:class:`bool`]
1190
            Toggles the user's suppress state |default| :data:`None`
1191
        request_to_speak_timestamp : Optional[:class:`~pincer.utils.timestamp.Timestamp`]
1192
            Sets the user's request to speak
1193
        """
1194
        await self._http.patch(
1195
            f"guilds/{self.id}/voice-states/@me",
1196
            data={
1197
                "channel_id": channel_id,
1198
                "suppress": suppress,
1199
                "request_to_speak_timestamp": request_to_speak_timestamp
1200
            }
1201
        )
1202
1203
    async def modify_user_voice_state(
1204
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1205
        user: User,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1206
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1207
        suppress: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1208
    ):
1209
        """|coro|
1210
        Updates another user's voice state.
1211
1212
        There are currently several caveats for this endpoint:
1213
        * ``channel_id`` must currently point to a stage channel
1214
        * User must already have joined ``channel_id``
1215
        * You must have the ``MUTE_MEMBERS`` permission.
1216
          (Since suppression is the only thing that is available currently.)
1217
        * When unsuppressed, non-bot users will have their
1218
          ``request_to_speak_timestamp`` set to the current time.
1219
          Bot users will not.
1220
        * When suppressed, the user will have their
1221
          ``request_to_speak_timestamp`` removed.
1222
1223
        Parameters
1224
        ----------
1225
        user : :class:`~pincer.objects.guild.member.Member`
1226
            The user to update
1227
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1228
            The ID of the channel the user is currently in
1229
        suppress : Optional[:class:`bool`]
1230
            Toggles the user's suppress state |default| :data:`None`
1231
        """
1232
        await self._http.patch(
1233
            f"guilds/{self.id}/voice-states/{user.id}",
1234
            data={
1235
                "channel_id": channel_id,
1236
                "suppress": suppress
1237
            }
1238
        )
1239
1240
    async def get_audit_log(self) -> AuditLog:
1241
        """|coro|
1242
        Returns an audit log object for the guild.
1243
        Requires the ``VIEW_AUDIT_LOG`` permission.
1244
1245
        Returns
1246
        -------
1247
        :class:`~pincer.objects.guild.audit_log.AuditLog`
1248
            The audit log object for the guild.
1249
        """
1250
        return AuditLog.from_dict(
1251
            construct_client_dict(
1252
                self._client,
1253
                await self._http.get(f"guilds/{self.id}/audit-logs")
1254
            )
1255
        )
1256
1257
    async def get_emojis(self) -> AsyncGenerator[Emoji, None]:
1258
        """|coro|
1259
        Returns an async generator of the emojis in the guild.
1260
1261
        Yields
1262
        ------
1263
        :class:`~pincer.objects.guild.emoji.Emoji`
1264
            The emoji object.
1265
        """
1266
        data = await self._http.get(f"guilds/{self.id}/emojis")
1267
        for emoji_data in data:
1268
            yield Emoji.from_dict(
1269
                construct_client_dict(self._client, emoji_data)
1270
            )
1271
1272
    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...
1273
        """|coro|
1274
        Returns an emoji object for the given ID.
1275
1276
        Parameters
1277
        ----------
1278
        id : :class:`~pincer.utils.snowflake.Snowflake`
1279
            The ID of the emoji
1280
1281
        Returns
1282
        -------
1283
        :class:`~pincer.objects.guild.emoji.Emoji`
1284
            The emoji object.
1285
        """
1286
        return Emoji.from_dict(
1287
            construct_client_dict(
1288
                self._client,
1289
                await self._http.get(f"guilds/{self.id}/emojis/{id}")
1290
            )
1291
        )
1292
1293
    async def create_emoji(
1294
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1295
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1296
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1297
        image: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1298
        roles: List[Snowflake],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1299
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1300
    ) -> Emoji:
1301
        """|coro|
1302
        Creates a new emoji for the guild.
1303
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1304
1305
        Emojis and animated emojis have a maximum file size of 256kb.
1306
        Attempting to upload an emoji larger than this limit will fail.
1307
1308
        Parameters
1309
        ----------
1310
        name : :class:`str`
1311
            Name of the emoji
1312
        image : :class:`str`
1313
            The 128x128 emoji image data
1314
        roles : List[:class:`~pincer.utils.snowflake.Snowflake`]
1315
            Roles allowed to use this emoji
1316
        reason : Optional[:class:`str`]
1317
            The reason for creating the emoji |default| :data:`None`
1318
1319
        Returns
1320
        -------
1321
        :class:`~pincer.objects.guild.emoji.Emoji`
1322
            The newly created emoji object.
1323
        """
1324
        data = await self._http.post(
1325
            f"guilds/{self.id}/emojis",
1326
            data={
1327
                "name": name,
1328
                "image": image,
1329
                "roles": roles
1330
            },
1331
            headers=remove_none({"X-Audit-Log-Reason": reason})
1332
        )
1333
        return Emoji.from_dict(
1334
            construct_client_dict(self._client, data)
1335
        )
1336
1337
    async def edit_emoji(
1338
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1339
        id: Snowflake,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1340
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1341
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1342
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1343
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1344
    ) -> Emoji:
1345
        """|coro|
1346
        Modifies the given emoji.
1347
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1348
1349
        Parameters
1350
        ----------
1351
        id : :class:`~pincer.utils.snowflake.Snowflake`
1352
            The ID of the emoji
1353
        name : Optional[:class:`str`]
1354
            Name of the emoji |default| :data:`None`
1355
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1356
            Roles allowed to use this emoji |default| :data:`None`
1357
        reason : Optional[:class:`str`]
1358
            The reason for editing the emoji |default| :data:`None`
1359
1360
        Returns
1361
        -------
1362
        :class:`~pincer.objects.guild.emoji.Emoji`
1363
            The modified emoji object.
1364
        """
1365
        data = await self._http.patch(
1366
            f"guilds/{self.id}/emojis/{id}",
1367
            data={
1368
                "name": name,
1369
                "roles": roles
1370
            },
1371
            headers=remove_none({"X-Audit-Log-Reason": reason})
1372
        )
1373
        return Emoji.from_dict(
1374
            construct_client_dict(self._client, data)
1375
        )
1376
1377
    async def delete_emoji(
1378
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1379
        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...
1380
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1381
        reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1382
    ):
1383
        """|coro|
1384
        Deletes the given emoji.
1385
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1386
1387
        Parameters
1388
        ----------
1389
        id : :class:`~pincer.utils.snowflake.Snowflake`
1390
            The ID of the emoji
1391
        reason : Optional[:class:`str`]
1392
            The reason for deleting the emoji |default| :data:`None`
1393
        """
1394
        await self._http.delete(
1395
            f"guilds/{self.id}/emojis/{id}",
1396
            headers=remove_none({"X-Audit-Log-Reason": reason})
1397
        )
1398
1399
    @classmethod
1400
    def from_dict(cls, data) -> Guild:
1401
        """
1402
        Parameters
1403
        ----------
1404
        data : :class:`Dict`
1405
            Guild data received from the discord API.
1406
        Returns
1407
        -------
1408
        :class:`~pincer.objects.guild.guild.Guild`
1409
            The new guild object.
1410
        Raises
1411
        :class:`~pincer.exceptions.UnavailableGuildError`
1412
            The guild is unavailable due to a discord outage.
1413
        """
1414
        if data.get("unavailable", False):
1415
            raise UnavailableGuildError(
1416
                f"Guild \"{data['id']}\" is unavailable due to a discord"
1417
                " outage."
1418
            )
1419
1420
        return super().from_dict(data)
1421
1422
1423
@dataclass
1424
class UnavailableGuild(APIObject):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
1425
    id: Snowflake
1426
    unavailable: bool = True
1427