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

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

Complexity

Conditions 1

Size

Total Lines 46
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 46
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 (1828/1000)
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from __future__ import annotations
5
6
from dataclasses import dataclass, field
7
from enum import IntEnum
8
from typing import AsyncGenerator, overload, TYPE_CHECKING
9
10
from .invite import Invite
11
from .channel import Channel
12
from ..message.emoji import Emoji
13
from ..message.file import File
14
from ...exceptions import UnavailableGuildError
15
from ...utils.api_object import APIObject
16
from ...utils.conversion import construct_client_dict, remove_none
17
from ...utils.types import MISSING
18
19
20
if TYPE_CHECKING:
21
    from typing import Any, Dict, List, Optional, Tuple, Union, Generator
22
    from .channel import PublicThread, PrivateThread, ChannelType
23
24
    from .audit_log import AuditLog
25
    from .ban import Ban
26
    from .member import GuildMember
27
    from .features import GuildFeature
28
    from .overwrite import Overwrite
29
    from .role import Role
30
    from .stage import StageInstance
31
    from .template import GuildTemplate
32
    from .welcome_screen import WelcomeScreen, WelcomeScreenChannel
33
    from .widget import GuildWidget
34
    from .webhook import Webhook
35
    from ..user.user import User
36
    from ..user.integration import Integration
37
    from ..voice.region import VoiceRegion
38
    from ..events.presence import PresenceUpdateEvent
39
    from ..message.sticker import Sticker
40
    from ..user.voice_state import VoiceState
41
    from ...client import Client
42
    from ...utils.timestamp import Timestamp
43
    from ...utils.types import APINullable, JSONSerializable
44
    from ...utils.snowflake import Snowflake
45
46
47
class PremiumTier(IntEnum):
48
    """Represents the boost tier of a guild.
49
    Attributes
50
    ----------
51
    NONE:
52
        Guild has not unlocked any Server Boost perks.
53
    TIER_1:
54
        Guild has unlocked Server Boost level 1 perks.
55
    TIER_2:
56
        Guild has unlocked Server Boost level 2 perks.
57
    TIER_3:
58
        Guild has unlocked Server Boost level 3 perks.
59
    """
60
61
    NONE = 0
62
    TIER_1 = 1
63
    TIER_2 = 2
64
    TIER_3 = 3
65
66
67
class GuildNSFWLevel(IntEnum):
68
    """Represents the NSFW level of a guild.
69
    Attributes
70
    ----------
71
    DEFAULT:
72
        Default NSFW level.
73
    EXPLICIT:
74
        Explicit NSFW level.
75
    SAFE:
76
        SAFE NSFW level.
77
    AGE_RESTRICTED:
78
        Age restricted NSFW level.
79
    """
80
81
    DEFAULT = 0
82
    EXPLICIT = 1
83
    SAFE = 2
84
    AGE_RESTRICTED = 3
85
86
87
class ExplicitContentFilterLevel(IntEnum):
88
    """Represents the filter content level of a guild.
89
    Attributes
90
    ----------
91
    DISABLED:
92
        Media content will not be scanned.
93
    MEMBERS_WITHOUT_ROLES:
94
        Media content sent by members without roles will be scanned.
95
    ALL_MEMBERS:
96
        Media content sent by all members will be scanned.
97
    """
98
99
    DISABLED = 0
100
    MEMBERS_WITHOUT_ROLES = 1
101
    ALL_MEMBERS = 2
102
103
104
class MFALevel(IntEnum):
105
    """Represents the multi factor authentication level of a guild.
106
    Attributes
107
    ----------
108
    NONE:
109
        Guild has no MFA/2FA requirement for moderation actions.
110
    ELEVATED:
111
        Guild has a 2FA requirement for moderation actions
112
    """
113
114
    NONE = 0
115
    ELEVATED = 1
116
117
118
class VerificationLevel(IntEnum):
119
    """Represents the verification level of a guild.
120
    Attributes
121
    ----------
122
    NONE:
123
        Unrestricted.
124
    LOW:
125
        Must have verified email on account.
126
    MEDIUM:
127
        Must be registered on Discord for longer than 5 minutes.
128
    HIGH:
129
        Must be a member of the server for longer than 10 minutes.
130
    VERY_HIGH:
131
        Must have a verified phone number.
132
    """
133
134
    NONE = 0
135
    LOW = 1
136
    MEDIUM = 2
137
    HIGH = 3
138
    VERY_HIGH = 4
139
140
141
class DefaultMessageNotificationLevel(IntEnum):
142
    """Represents the default message notification level of a guild.
143
    Attributes
144
    ----------
145
    ALL_MESSAGES:
146
        Members will receive notifications for all messages by default.
147
    ONLY_MENTIONS:
148
        Members will receive notifications only for messages that @mention them by default.
149
    """
150
151
    # noqa: E501
152
    ALL_MESSAGES = 0
153
    ONLY_MENTIONS = 1
154
155
156
class SystemChannelFlags(IntEnum):
157
    """Represents the system channel flags of a guild.
158
    Attributes
159
    ----------
160
    SUPPRESS_JOIN_NOTIFICATIONS:
161
        Suppress member join notifications.
162
    SUPPRESS_PREMIUM_SUBSCRIPTIONS:
163
        Suppress server boost notifications.
164
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS:
165
        Suppress server setup tips.
166
    SUPPRESS_JOIN_NOTIFICATION_REPLIES:
167
        Hide member join sticker reply buttons
168
    """
169
170
    SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0
171
    SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
172
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS = 1 << 2
173
    SUPPRESS_JOIN_NOTIFICATION_REPLIES = 1 << 3
174
175
176
177
@dataclass(repr=False)
178
class GuildPreview(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (10/7)
Loading history...
179
    """Represents a guild preview.
180
    Attributes
181
    ----------
182
    id: :class:`Snowflake`
183
        The guild ID.
184
    name: :class:`str`
185
        The guild name.
186
    icon: :class:`str`
187
        The guild icon hash.
188
    splash: :class:`str`
189
        The guild splash hash.
190
    discovery_splash: :class:`str`
191
        The guild discovery splash hash.
192
    emojis: :class:`List[Emoji]`
193
        The guild emojis.
194
    features: :class:`List[GuildFeature]`
195
        The guild features.
196
    approximate_member_count: :class:`int`
197
        The approximate member count.
198
    approximate_presence_count: :class:`int`
199
        The approximate number of online members in this guild
200
    description: :class:`str`
201
        The guild description.
202
    """
203
204
    id: Snowflake
205
    name: str
206
    emojis: List[Emoji]
207
    features: List[GuildFeature]
208
    approximate_member_count: int
209
    approximate_presence_count: int
210
211
    icon: APINullable[str] = MISSING
212
    splash: APINullable[str] = MISSING
213
    discovery_splash: APINullable[str] = MISSING
214
    description: APINullable[str] = MISSING
215
216
217
@dataclass(repr=False)
218
class Guild(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (59/7)
Loading history...
best-practice introduced by
Too many public methods (54/20)
Loading history...
219
    """Represents a Discord guild/server in which your client resides.
220
    Attributes
221
    ----------
222
    afk_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
223
        Id of afk channel
224
    afk_timeout: :class:`int`
225
        Afk timeout in seconds
226
    application_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
227
        Application id of the guild creator if it is bot-created
228
    banner: Optional[:class:`str`]
229
        Banner hash
230
    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...
231
        Default message notifications level
232
    description: Optional[:class:`str`]
233
        The description of a Community guild
234
    discovery_splash: Optional[:class:`str`]
235
        Discovery splash hash;
236
        only present for guilds with the "DISCOVERABLE" feature
237
    emojis: List[:class:`~pincer.objects.message.emoji.Emoji`]
238
        Custom guild emojis
239
    explicit_content_filter: :class:`~pincer.objects.guild.guild.ExplicitContentFilterLevel`
240
        Explicit content filter level
241
    features: List[:class:`~pincer.objects.guild.features.GuildFeature`]
242
        Enabled guild features
243
    id: :class:`~pincer.utils.snowflake.Snowflake`
244
        Guild id
245
    icon: Optional[:class:`str`]
246
        Icon hash
247
    mfa_level: :class:`~pincer.objects.guild.guild.MFALevel`
248
        Required MFA level for the guild
249
    name: :class:`str`
250
        Guild name (2-100 characters, excluding trailing and leading
251
        whitespace)
252
    nsfw_level: :class:`~pincer.objects.guild.guild.NSFWLevel`
253
        Guild NSFW level
254
    owner_id: :class:`~pincer.utils.snowflake.Snowflake`
255
        Id of owner
256
    preferred_locale: :class:`str`
257
        The preferred locale of a Community guild;
258
        used in server discovery and notices from Discord;
259
        defaults to "en-US"
260
    premium_tier: :class:`~pincer.objects.guild.guild.PremiumTier`
261
        Premium tier (Server Boost level)
262
    public_updates_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
263
        The id of the channel where admins
264
        and moderators of Community guilds receive notices from Discord
265
    roles: List[:class:`~pincer.objects.guild.role.Role`]
266
        Roles in the guild
267
    rules_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
268
        The id of the channel where Community guilds can display rules
269
        and/or guidelines
270
    splash: Optional[:class:`str`]
271
        Splash hash
272
    system_channel_flags: :class:`~pincer.objects.guild.guild.SystemChannelFlags`
273
        System channel flags
274
    system_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
275
        The id of the channel where guild notices
276
        such as welcome messages and boost events are posted
277
    vanity_url_code: Optional[:class:`str`]
278
        The vanity url code for the guild
279
    verification_level: :class:`~pincer.objects.guild.guild.VerificationLevel`
280
        Verification level required for the guild
281
    approximate_member_count: APINullable[:class:`int`]
282
        Approximate number of members in this guild, returned from the
283
        `GET /guilds/<id>` endpoint when with_counts is true
284
    approximate_presence_count: APINullable[:class:`int`]
285
        Approximate number of non-offline members in this guild,
286
        returned from the `GET /guilds/<id>`
287
        endpoint when with_counts is true
288
    channels: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
289
        Channels in the guild
290
    icon_hash: APINullable[Optional[:class:`str`]]
291
        Icon hash, returned when in the template object
292
    joined_at: APINullable[:class:`~pincer.utils.timestamp.Timestamp`]
293
        When this guild was joined at
294
    large: APINullable[:class:`bool`]
295
        True if this is considered a large guild
296
    max_members: APINullable[:class:`int`]
297
        The maximum number of members for the guild
298
    max_presences: APINullable[Optional[:class:`int`]]
299
        The maximum number of presences for the guild
300
        (null is always returned, apart from the largest of guilds)
301
    max_video_channel_users: APINullable[:class:`int`]
302
        The maximum amount of users in a video channel
303
    members: APINullable[List[:class:`~pincer.objects.guild.member.GuildMember`]]
304
        Users in the guild
305
    member_count: APINullable[:class:`bool`]
306
        Total number of members in this guild
307
    nsfw: APINullable[:class:`bool`]
308
        Boolean if the server is NSFW
309
    owner: APINullable[:class:`bool`]
310
        True if the user is the owner of the guild
311
    permissions: APINullable[:class:`str`]
312
        Total permissions for the user in the guild
313
        (excludes overwrites)
314
    premium_subscription_count: APINullable[:class:`int`]
315
        The number of boosts this guild currently has
316
    presences: APINullable[List[:class:`~pincer.objects.events.presence.PresenceUpdateEvent`]]
317
        Presences of the members in the guild,
318
        will only include non-offline members if the size is greater
319
        than large threshold
320
    stage_instances: APINullable[List[:class:`~pincer.objects.guild.stage.StageInstance`]]
321
        Stage instances in the guild
322
    stickers: Optional[List[:class:`~pincer.objects.message.sticker.Sticker`]]
323
        Custom guild stickers
324
    region: APINullable[Optional[:class:`str`]]
325
        Voice region id for the guild (deprecated)
326
    threads: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
327
        All active threads in the guild that current user
328
        has permission to view
329
    unavailable: APINullable[:class:`bool`]
330
        True if this guild is unavailable due to an outage
331
    voice_states: APINullable[List[:class:`~pincer.objects.user.voice_state.VoiceState`]]
332
        States of members currently in voice channels;
333
        lacks the guild_id key
334
    widget_enabled: APINullable[:class:`bool`]
335
        True if the server widget is enabled
336
    widget_channel_id: APINullable[Optional[:class:`~pincer.utils.snowflake.Snowflake`]]
337
        The channel id that the widget will generate an invite to,
338
        or null if set to no invite
339
    welcome_screen: APINullable[:class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`]
340
        The welcome screen of a Community guild, shown to new members,
341
        returned in an Invite's guild object
342
    """
343
344
    # noqa: E501
345
    features: List[GuildFeature]
346
    id: Snowflake
347
    name: str
348
    nsfw_level: GuildNSFWLevel
349
    verification_level: VerificationLevel
350
351
    # Guild invites missing
352
    system_channel_flags: APINullable[SystemChannelFlags] = MISSING
353
    explicit_content_filter: APINullable[ExplicitContentFilterLevel] = MISSING
354
    premium_tier: APINullable[PremiumTier] = MISSING
355
    default_message_notifications: APINullable[DefaultMessageNotificationLevel] = MISSING
356
    mfa_level: APINullable[MFALevel] = MISSING
357
    owner_id: APINullable[Snowflake] = MISSING
358
    afk_timeout: APINullable[int] = MISSING
359
    emojis: APINullable[List[Emoji]] = MISSING
360
    preferred_locale: APINullable[str] = MISSING
361
    roles: APINullable[List[Role]] = MISSING
362
363
    guild_scheduled_events: APINullable[List] = MISSING
364
    lazy: APINullable[bool] = MISSING
365
    premium_progress_bar_enabled: APINullable[bool] = MISSING
366
    guild_hashes: APINullable[Dict] = MISSING
367
    afk_channel_id: APINullable[Snowflake] = MISSING
368
    application_id: APINullable[Snowflake] = MISSING
369
    embedded_activities: APINullable[List] = MISSING
370
    banner: APINullable[str] = MISSING
371
    description: APINullable[str] = MISSING
372
    discovery_splash: APINullable[str] = MISSING
373
    icon: APINullable[str] = MISSING
374
    public_updates_channel_id: APINullable[Snowflake] = MISSING
375
    rules_channel_id: APINullable[Snowflake] = MISSING
376
    splash: APINullable[str] = MISSING
377
    system_channel_id: APINullable[Snowflake] = MISSING
378
    vanity_url_code: APINullable[str] = MISSING
379
380
    application_command_counts: APINullable[Dict] = MISSING
381
    application_command_count: APINullable[int] = MISSING
382
    approximate_member_count: APINullable[int] = MISSING
383
    approximate_presence_count: APINullable[int] = MISSING
384
    channels: APINullable[List[Channel]] = field(default_factory=list)
385
    # 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...
386
    hub_type: APINullable[Any] = MISSING
387
    icon_hash: APINullable[Optional[str]] = MISSING
388
    joined_at: APINullable[Timestamp] = MISSING
389
    large: APINullable[bool] = MISSING
390
    max_members: APINullable[int] = MISSING
391
    max_presences: APINullable[Optional[int]] = MISSING
392
    max_video_channel_users: APINullable[int] = MISSING
393
    members: APINullable[List[GuildMember]] = MISSING
394
    member_count: APINullable[bool] = MISSING
395
    nsfw: APINullable[bool] = MISSING
396
    # Note: This is missing from discord's docs but in the api
397
    owner: APINullable[bool] = MISSING
398
    permissions: APINullable[str] = MISSING
399
    premium_subscription_count: APINullable[int] = MISSING
400
    presences: APINullable[List[PresenceUpdateEvent]] = MISSING
401
    stage_instances: APINullable[List[StageInstance]] = MISSING
402
    stickers: APINullable[List[Sticker]] = MISSING
403
    region: APINullable[Optional[str]] = MISSING
404
    threads: APINullable[List[Channel]] = MISSING
405
    # Guilds are considered available unless otherwise specified
406
    unavailable: APINullable[bool] = False
407
    voice_states: APINullable[List[VoiceState]] = MISSING
408
    widget_enabled: APINullable[bool] = MISSING
409
    widget_channel_id: APINullable[Optional[Snowflake]] = MISSING
410
    welcome_screen: APINullable[WelcomeScreen] = MISSING
411
412
    @classmethod
413
    async def from_id(cls, client: Client, _id: Union[int, Snowflake]) -> Guild:
414
        """
415
        Parameters
416
        ----------
417
        client : :class:`~pincer.Client`
418
            Client object to use the http gateway from.
419
        _id : :class:`pincer.utils.snowflake.Snowflake`
420
            Guild ID.
421
        Returns
422
        -------
423
        :class:`~pincer.objects.guild.guild.Guild`
424
            The new guild object.
425
        """
426
        data = await client.http.get(f"/guilds/{_id}")
427
        channel_data = await client.http.get(f"/guilds/{_id}/channels")
428
429
        data["channels"]: List[Channel] = [
430
            Channel.from_dict(construct_client_dict(client, i))
431
            for i in (channel_data or [])
432
        ]
433
434
        return Guild.from_dict(construct_client_dict(client, data))
435
436
    async def get_member(self, _id: int) -> GuildMember:
437
        """|coro|
438
        Fetches a GuildMember from its identifier
439
440
        Parameters
441
        ----------
442
        _id: int
443
            The id of the guild member which should be fetched from the Discord
444
            gateway.
445
        Returns
446
        -------
447
        :class:`~pincer.objects.guild.member.GuildMember`
448
            A GuildMember object.
449
        """
450
        return await GuildMember.from_id(self._client, self.id, _id)
451
452
    @overload
453
    async def modify_member(
454
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
455
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
456
        _id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
457
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
458
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
459
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
460
        deaf: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
461
        channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
462
    ) -> GuildMember:
463
        """|coro|
464
        Modifies a member in the guild from its identifier and based on the
465
        keyword arguments provided.
466
        Parameters
467
        ----------
468
        _id : int
469
            Id of the member to modify
470
        nick : Optional[:class:`str`]
471
            New nickname for the member |default| :data:`None`
472
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake]]
473
            New roles for the member |default| :data:`None`
474
        mute : Optional[:class:`bool`]
475
            Whether the member is muted |default| :data:`None`
476
        deaf : Optional[:class:`bool`]
477
            Whether the member is deafened |default| :data:`None`
478
        channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake]
479
            Voice channel id to move to |default| :data:`None`
480
        Returns
481
        -------
482
        :class:`~pincer.objects.guild.member.GuildMember`
483
            The new member object.
484
        """
485
        ...
486
487
    async def modify_member(self, _id: int, **kwargs) -> GuildMember:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
488
        data = await self._http.patch(
489
            f"guilds/{self.id}/members/{_id}", data=kwargs
490
        )
491
        return GuildMember.from_dict(construct_client_dict(self._client, data))
492
493
      
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
494
    @overload
495
    async def create_channel(
0 ignored issues
show
best-practice introduced by
Too many arguments (11/5)
Loading history...
496
        self, 
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
497
        name: str,               
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
498
        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...
499
        topic: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
500
        bitrate: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
501
        user_limit: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
502
        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...
503
        position: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
504
        permission_overwrites: Optional[List[Overwrite]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
505
        parent_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
506
        nsfw: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
507
    ) -> Channel:
508
        """|coro|
509
        Create a new channel object for the guild.
510
511
        Parameters
512
        ----------
513
        name : str
514
            channel name (1-100 characters)
515
        type : Optional[:class:int`]
516
            the type of channel
517
        topic : Optional[:class:str`]
518
            channel topic (0-1024 characters)
519
        bitrate : Optional[:class:`int`]
520
            the bitrate (in bits) of the voice channel (voice only)
521
        user_limit : Optional[:class:`int`]
522
            the user limit of the voice channel (voice only)
523
        rate_limit_per_user : Optional[:class:`int`]
524
            amount of seconds a user has to wait before sending another message (0-21600)
525
            bots, as well as users with the permission manage_messages or manage_channel, are unaffected
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

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

Loading history...
526
        position : Optional[:class:`int`]
527
            sorting position of the channel
528
        permission_overwrites : Optional[List[:class:`~pincer.objects.guild.overwrite.Overwrite`]]
529
            the channel's permission overwrites
530
        parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
531
            id of the parent category for a channel
532
        nsfw : Optional[:class:`bool`]
533
            whether the channel is nsfw
534
        Returns
535
        -------
536
        :class:`~pincer.objects.guild.channel.Channel`
537
            The new channel object.
538
        """
539
        ...
540
541
    async def create_channel(self, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
542
        data = await self._http.post(f"guilds/{self.id}/channels", data=kwargs)
543
        return Channel.from_dict(construct_client_dict(self._client, data))
544
545
    async def modify_channel_positions(
546
        self, *channel: Dict[str, Optional[Union[int, bool, Snowflake]]]
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
547
    ):
548
        """|coro|
549
        Create a new channel object for the guild.
550
551
        Parameters
552
        ----------
553
554
        \\*channel : Dict[str, Optional[Union[int, bool, :class:`~pincer.utils.snowflake.Snowflake`]
555
            Keys:
556
                - id : :class:`~pincer.utils.snowflake.Snowflake`
557
                - position : Optional[:class:`int`]
558
                - lock_permissions : Optional[:class:`bool`]
559
                - parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
560
        """
561
        await self._http.patch(f"guilds/{self.id}/channels", data=channel)
562
563
    async def list_active_threads(self) -> Tuple[
564
        Generator[Union[PublicThread, PrivateThread]], Generator[GuildMember]]:
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
565
        """|coro|
566
        Returns all active threads in the guild, including public and private threads.
567
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
568
        Returns
569
        -------
570
        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...
571
            The new member object.
572
        """
573
        data = await self._http.get(f"guilds/{self.id}/threads/active")
574
575
        threads = (
576
            Channel.from_dict(construct_client_dict(self._client, data))
577
            for channel in data["threads"]
578
        )
579
        members = (
580
            GuildMember.from_dict(construct_client_dict(self._client, data))
581
            for member in data["members"]
582
        )
583
584
        return threads, members
585
586
    async def list_guild_members(self, limit: int = 1, after: int = 0):
587
        """|coro|
588
        Returns a list of guild member objects that are members of the guild.
589
590
        Parameters
591
        ----------
592
        limit : int
593
            max number of members to return (1-1000) |default| :data:`1`
594
        after : int
595
            the highest user id in the previous page |default| :data:`0`
596
        """
597
598
        members = await self._http.get(
599
            f"guilds/{self.id}/members?{limit=!s}&{after=!s}"
600
        )
601
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
602
        return (GuildMember.from_dict(construct_client_dict(self._client, data)) for member in members)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

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

Loading history...
Comprehensibility Best Practice introduced by
Undefined variable 'data'
Loading history...
603
604
    async def search_guild_members(
605
        self, 
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Coding Style introduced by
Trailing whitespace
Loading history...
606
        query: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
607
        limit: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
608
    ) -> List[GuildMember]:
609
        """|coro|
610
        Returns a list of guild member objects whose username or nickname starts with a provided string.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

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

Loading history...
611
612
        Parameters
613
        ----------
614
        query : str
615
            Query string to match username(s) and nickname(s) against.
616
        limit : Optional[int]
617
            max number of members to return (1-1000) |default| :data:`1`
618
        Returns
619
        -------
620
        List[:class:`~pincer.objects.guild.member.GuildMember`]
621
            list of guild member objects
622
        """
623
624
        data = await self._http.get(
625
            f"guilds/{id}/members/search?{query=!s}"
626
            f"&{limit}" if limit else ""
627
        )
628
629
        return (GuildMember.from_dict(member) for member in data)
630
631
    @overload
632
    async def add_guild_member(
633
        self, *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
634
        user_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
635
        access_token: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
636
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
637
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
638
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
639
        deaf: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
640
    ) -> Optional[GuildMember]:
641
        """|coro|
642
        Adds a user to the guild, provided you have a valid oauth2 access token for the user with the guilds.join scope.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (120/100).

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

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

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

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

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