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

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

Complexity

Conditions 1

Size

Total Lines 43
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

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

Loading history...
493
        topic: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
494
        bitrate: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
495
        user_limit: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
496
        rate_limit_per_user: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
497
        position: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
498
        permission_overwrites: Optional[List[Overwrite]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
499
        parent_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
500
        nsfw: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
501
    ) -> Channel:
502
        """|coro|
503
        Create a new channel object for the guild.
504
505
        Parameters
506
        ----------
507
        name : str
508
            channel name (1-100 characters)
509
        type : Optional[:class:int`]
510
            the type of channel
511
        topic : Optional[:class:str`]
512
            channel topic (0-1024 characters)
513
        bitrate : Optional[:class:`int`]
514
            the bitrate (in bits) of the voice channel (voice only)
515
        user_limit : Optional[:class:`int`]
516
            the user limit of the voice channel (voice only)
517
        rate_limit_per_user : Optional[:class:`int`]
518
            amount of seconds a user has to wait before sending another message (0-21600)
519
            bots, as well as users with the permission manage_messages or manage_channel, are unaffected
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

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

Loading history...
520
        position : Optional[:class:`int`]
521
            sorting position of the channel
522
        permission_overwrites : Optional[List[:class:`~pincer.objects.guild.overwrite.Overwrite`]]
523
            the channel's permission overwrites
524
        parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
525
            id of the parent category for a channel
526
        nsfw : Optional[:class:`bool`]
527
            whether the channel is nsfw
528
529
        """
530
        ...
531
532
    async def create_channel(self, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
533
        data = await self._http.post(f"guilds/{self.id}/channels", data=kwargs)
534
        return Channel.from_dict(construct_client_dict(self._client, data))
535
536
    async def modify_channel_positions(
537
        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...
538
    ):
539
        """|coro|
540
        Create a new channel object for the guild.
541
542
        Parameters
543
        ----------
544
545
        \\*channel : Dict[str, Optional[Union[int, bool, :class:`~pincer.utils.snowflake.Snowflake`]
546
            Keys:
547
                - id : :class:`~pincer.utils.snowflake.Snowflake`
548
                - position : Optional[:class:`int`]
549
                - lock_permissions : Optional[:class:`bool`]
550
                - parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
551
552
        """
553
554
    async def list_active_threads(self) -> Tuple[
555
        Generator[Union[PublicThread, PrivateThread]], Generator[GuildMember]]:
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
556
        """|coro|
557
        Returns all active threads in the guild, including public and private threads.
558
        """
559
        data = await self._http.get(f"guilds/{self.id}/threads/active")
560
561
        threads = (Channel.from_dict(channel) for channel in data["threads"])
562
        members = (GuildMember.from_dict(member) for member in data["members"])
563
564
        return threads, members
565
566
    async def list_guild_members(self, limit: int = 1, after: int = 0):
567
        """|coro|
568
        Returns a list of guild member objects that are members of the guild.
569
570
        Parameters
571
        ----------
572
        limit : int
573
            max number of members to return (1-1000) |default| :data:`1`
574
        after : int
575
            the highest user id in the previous page |default| :data:`0`
576
        """
577
578
        members = await self._http.get(
579
            f"guilds/{self.id}/members?limit={limit}&after={after}"
580
        )
581
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
582
        return (GuildMember.from_dict(memeber) for member in members)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'memeber'
Loading history...
583
584
    async def search_guild_members(
585
        self, query: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
586
        limit: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
587
    ) -> List[GuildMember]:
588
        """|coro|
589
        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...
590
591
        Parameters
592
        ----------
593
        query : str
594
            Query string to match username(s) and nickname(s) against.
595
        limit : Optional[int]
596
            max number of members to return (1-1000) |default| :data:`1`
597
598
        """
599
600
        data = await self._http.get(
601
            f"guilds/{id}/members/search?query={query}"
602
            f"&{limit}" if limit else ""
603
        )
604
605
        return [GuildMember.from_dict(member) for member in data]
606
607
    @overload
608
    async def add_guild_member(
609
        self, *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
610
        user_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
611
        access_token: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
612
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
613
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
614
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
615
        deaf: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
616
    ) -> Optional[GuildMember]:
617
        """|coro|
618
        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...
619
620
        Parameters
621
        ----------
622
        user_id : str
623
            id of the user to be added
624
        access_token : str
625
            an oauth2 access token granted with the guilds.join to the bot's application for the user you want to add to the guild
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (130/100).

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

Loading history...
626
        nick : Optional[str]
627
        	value to set users nickname to
628
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
629
        	array of role ids the member is assigned
630
        mute : Optional[bool]
631
        	whether the user is muted in voice channels
632
        deaf : Optional[bool]
633
        	whether the user is deafened in voice channels
634
635
        Returns
636
        -------
637
        :class:`~pincer.objects.guild.member.GuildMember`
638
            If the user is not in the guild
639
        None
640
            If the user is in the guild
641
        """
642
643
    async def add_guild_member(self, user_id, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
644
        data = self._http.put(f"guilds/{self.id}/members/{user_id}",
645
                              data=kwargs)
646
647
        return GuildMember.from_dict(data) if data else None
648
649
    async def modify_current_member(self, nick: str) -> GuildMember:
650
        """|coro|
651
        Modifies the current member in a guild.
652
653
        Parameters
654
        ----------
655
        nick : str
656
            value to set users nickname to
657
        """
658
        data = self._http.patch(f"guilds/{self.id}/members/@me", {"nick": nick})
659
        member = GuildMember.from_dict(data)
660
        return member
661
662
    async def add_guild_member_role(self, user_id: int, role_id: int) -> None:
663
        """|coro|
664
        Adds a role to a guild member.
665
666
        Parameters
667
        ----------
668
        user_id : int
669
            id of the user to give a role to
670
        role_id : int
671
            id of a role
672
        """
673
        data = await self._http.put(
0 ignored issues
show
Unused Code introduced by
The variable data seems to be unused.
Loading history...
674
            f"guilds/{self.id}/{user_id}/roles/{role_id}", {})
675
        # TODO: remove the blank dictionary once #233 is fixed
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
676
677
    async def remove_guild_member_role(self, user_id: int,
678
                                       role_id: int) -> None:
679
        """|coro|
680
        Removes a role from a guild member.
681
682
        Parameters
683
        ----------
684
        user_id : int
685
            id of the user to remove a role from
686
        role_id : int
687
            id of a role
688
        """
689
        await self._http.delete(
690
            f"guilds/{self.id}/{user_id}/roles/{role_id}",
691
        )
692
        # TODO: remove the blank dictionary and format once #233 is fixed
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
693
694
    async def remove_guild_member(self, user_id: int) -> None:
695
        """|coro|
696
        Remove a member from a guild.
697
698
        Parameters
699
        ----------
700
        user_id : int
701
            id of the user to remove from the guild
702
        """
703
        await self._http.delete(f"guilds/{self.id}/members/{user_id}")
704
705
    async def ban(
706
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
707
        member_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
708
        reason: str = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
709
        delete_message_days: int = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
710
    ):
711
        """
712
        Parameters
713
        ----------
714
        member_id : :class:`int`
715
            ID of the guild member to ban.
716
        reason : Optional[:class:`str`]
717
            Reason for the kick.
718
        delete_message_days : Optional[:class:`int`]
719
            Number of days to delete messages for (0-7)
720
        """
721
        headers = {}
722
723
        if reason is not None:
724
            headers["X-Audit-Log-Reason"] = reason
725
726
        data = {}
727
728
        if delete_message_days is not None:
729
            data["delete_message_days"] = delete_message_days
730
731
        await self._http.put(
732
            f"/guilds/{self.id}/bans/{member_id}",
733
            data=data,
734
            headers=headers
735
        )
736
737
    async def kick(self, member_id: int, reason: Optional[str] = None):
738
        """|coro|
739
        Kicks a guild member.
740
        Parameters
741
        ----------
742
        member_id : :class:`int`
743
            ID of the guild member to kick.
744
        reason : Optional[:class:`str`]
745
            Reason for the kick.
746
        """
747
748
        headers = {}
749
750
        if reason is not None:
751
            headers["X-Audit-Log-Reason"] = reason
752
753
        await self._http.delete(
754
            f"/guilds/{self.id}/members/{member_id}",
755
            header=headers
756
        )
757
758
    async def get_roles(self) -> AsyncGenerator[Role, None]:
759
        """|coro|
760
        Fetches all the roles in the guild.
761
762
        Yields
763
        -------
764
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
765
            An async generator of Role objects.
766
        """
767
        data = await self._http.get(f"guilds/{self.id}/roles")
768
        for role_data in data:
769
            yield Role.from_dict(construct_client_dict(self._client, role_data))
770
771
    @overload
772
    async def create_role(
773
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
774
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
775
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
776
        name: Optional[str] = "new role",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
777
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
778
        color: Optional[int] = 0,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
779
        hoist: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
780
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
781
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
782
        mentionable: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
783
    ) -> Role:
784
        """|coro|
785
        Creates a new role for the guild.
786
        Requires the ``MANAGE_ROLES`` permission.
787
788
        Parameters
789
        ----------
790
        reason : Optional[:class:`str`]
791
            Reason for creating the role. |default| :data:`None`
792
        name : Optional[:class:`str`]
793
            name of the role |default| :data:`"new role"`
794
        permissions : Optional[:class:`str`]
795
            bitwise value of the enabled/disabled
796
            permissions, set to @everyone permissions
797
            by default |default| :data:`None`
798
        color : Optional[:class:`int`]
799
            RGB color value |default| :data:`0`
800
        hoist : Optional[:class:`bool`]
801
            whether the role should be displayed
802
            separately in the sidebar |default| :data:`False`
803
        icon : Optional[:class:`str`]
804
            the role's icon image (if the guild has
805
            the ``ROLE_ICONS`` feature) |default| :data:`None`
806
        unicode_emoji : Optional[:class:`str`]
807
            the role's unicode emoji as a standard emoji (if the guild
808
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
809
        mentionable : Optional[:class:`bool`]
810
            whether the role should be mentionable |default| :data:`False`
811
812
        Returns
813
        -------
814
        :class:`~pincer.objects.guild.role.Role`
815
            The new role object.
816
        """
817
        ...
818
819
    async def create_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
820
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
821
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
822
        **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
823
    ) -> Role:
824
        return Role.from_dict(
825
            construct_client_dict(
826
                self._client,
827
                await self._http.post(
828
                    f"guilds/{self.id}/roles",
829
                    data=kwargs,
830
                    headers=remove_none({"X-Audit-Log-Reason": reason})
831
                ),
832
            )
833
        )
834
835
    async def edit_role_position(
836
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
837
        id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
838
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
839
        position: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
840
    ) -> AsyncGenerator[Role, None]:
841
        """|coro|
842
        Edits the position of a role.
843
844
        Parameters
845
        ----------
846
        id : :class:`~pincer.utils.snowflake.Snowflake`
847
            The role ID
848
        reason : Optional[:class:`str`]
849
            Reason for editing the role position. |default| :data:`None`
850
        position : Optional[:class:`int`]
851
            Sorting position of the role |default| :data:`None`
852
853
        Yields
854
        -------
855
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
856
            An async generator of all of the guild's role objects.
857
        """
858
        data = await self._http.patch(
859
            f"guilds/{self.id}/roles",
860
            data={"id": id, "position": position},
861
            headers=remove_none({"X-Audit-Log-Reason": reason})
862
        )
863
        for role_data in data:
864
            yield Role.from_dict(construct_client_dict(self._client, role_data))
865
866
    @overload
867
    async def edit_role(
868
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
869
        id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
870
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
871
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
872
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
873
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
874
        color: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
875
        hoist: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
876
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
877
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
878
        mentionable: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
879
    ) -> Role:
880
        """|coro|
881
        Edits a role.
882
        Requires the ``MANAGE_ROLES`` permission.
883
884
        Parameters
885
        ----------
886
        id : :class:`~pincer.utils.snowflake.Snowflake`
887
            The role ID
888
        reason : Optional[:class:`str`]
889
            Reason for editing the role |default| :data:`None`
890
        name : Optional[:class:`str`]
891
            Name of the role |default| :data:`None`
892
        permissions : Optional[:class:`str`]
893
            Bitwise value of the enabled/disabled
894
            permissions |default| :data:`None`
895
        color : Optional[:class:`int`]
896
            RGB color value |default| :data:`None`
897
        hoist : Optional[:class:`bool`]
898
            Whether the role should be displayed
899
            separately in the sidebar |default| :data:`None`
900
        icon : Optional[:class:`str`]
901
            The role's icon image (if the guild has
902
            the ``ROLE_ICONS`` feature) |default| :data:`None`
903
        unicode_emoji : Optional[:class:`str`]
904
            The role's unicode emoji as a standard emoji (if the guild
905
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
906
        mentionable : Optional[:class:`bool`]
907
            Whether the role should be mentionable |default| :data:`None`
908
909
        Returns
910
        -------
911
        :class:`~pincer.objects.guild.role.Role`
912
            The edited role object.
913
        """
914
        ...
915
916
    async def edit_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
917
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
918
        id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

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