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

pincer.objects.guild.guild   F

Complexity

Total Complexity 86

Size/Duplication

Total Lines 1948
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 86
eloc 594
dl 0
loc 1948
rs 2
c 0
b 0
f 0

60 Methods

Rating   Name   Duplication   Size   Complexity  
A Guild.edit_role_position() 0 30 2
A Guild.create_role() 0 47 1
A Guild.prune_count() 0 25 1
A Guild.modify_member() 0 42 2
A Guild.add_guild_member_role() 0 18 1
A Guild.unban() 0 14 1
A Guild.delete() 0 5 1
A Guild.get_ban() 0 16 1
A Guild.get_bans() 0 12 2
A Guild.prune() 0 38 1
A Guild.modify_channel_positions() 0 23 1
A Guild.create_channel() 0 51 1
A Guild.get_roles() 0 12 2
A Guild.delete_role() 0 15 1
A Guild.edit_role() 0 49 1
A Guild.list_guild_members() 0 25 2
A Guild.get_member() 0 15 1
A Guild.get_invites() 0 13 2
A Guild.edit() 0 83 1
A Guild.search_guild_members() 0 27 2
A Guild.preview() 0 11 1
A Guild.modify_current_member() 0 23 1
A Guild.remove_guild_member() 0 16 1
A Guild.remove_guild_member_role() 0 18 1
A Guild.get_voice_regions() 0 12 2
A Guild.ban() 0 28 3
A Guild.kick() 0 18 2
A Guild.add_guild_member() 0 13 2
A Guild.list_active_threads() 0 18 1
A Guild.from_id() 0 31 2
A Guild.get_integrations() 0 13 2
A Guild.delete_integration() 0 17 1
A Guild.get_invite() 0 16 1
A Guild.get_audit_log() 0 12 1
A Guild.get_widget_settings() 0 12 1
A Guild.delete_template() 0 19 1
A Guild.from_dict() 0 23 2
A Guild.edit_template() 0 32 1
A Guild.delete_invite() 0 11 1
A Guild.modify_widget() 0 25 1
A Guild.get_widget() 0 5 1
A Guild.modify_welcome_screen() 0 39 1
A Guild.create_emoji() 0 39 2
A Guild.create_template() 0 24 1
A Guild.edit_emoji() 0 34 1
A Guild.modify_current_user_voice_state() 0 34 1
A Guild.get_widget_image() 0 37 1
A Guild.get_webhooks() 0 12 2
A Guild.get_emoji() 0 16 1
A Guild.get_templates() 0 12 2
A Guild.list_stickers() 0 14 2
A Guild.delete_emoji() 0 17 1
A Guild.sync_template() 0 19 1
A Guild.vanity_url() 0 14 1
A Guild.get_welcome_screen() 0 10 1
A Guild.get_emojis() 0 12 2
A Guild.get_sticker() 0 18 1
A Guild.modify_user_voice_state() 0 29 1
A Guild.delete_sticker() 0 11 1
A Guild.create_sticker() 0 47 1

How to fix   Complexity   

Complexity

Complex classes like pincer.objects.guild.guild often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

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

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

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

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

Loading history...
524
        topic: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
525
        bitrate: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
526
        user_limit: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
527
        rate_limit_per_user: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
528
        position: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
529
        permission_overwrites: Optional[List[Overwrite]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
530
        parent_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
531
        nsfw: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
532
    ) -> Channel:
533
        """|coro|
534
        Create a new channel object for the guild.
535
536
        Parameters
537
        ----------
538
        name : str
539
            channel name (1-100 characters)
540
        type : Optional[:class:int`]
541
            the type of channel
542
        topic : Optional[:class:str`]
543
            channel topic (0-1024 characters)
544
        bitrate : Optional[:class:`int`]
545
            the bitrate (in bits) of the voice channel (voice only)
546
        user_limit : Optional[:class:`int`]
547
            the user limit of the voice channel (voice only)
548
        rate_limit_per_user : Optional[:class:`int`]
549
            amount of seconds a user has to wait
550
            before sending another message (0-21600)
551
            bots, as well as users with the permission
552
            manage_messages or manage_channel, are unaffected
553
        position : Optional[:class:`int`]
554
            sorting position of the channel
555
        permission_overwrites : Optional[List[:class:`~pincer.objects.guild.overwrite.Overwrite`]]
556
            the channel's permission overwrites
557
        parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
558
            id of the parent category for a channel
559
        nsfw : Optional[:class:`bool`]
560
            whether the channel is nsfw
561
        reason : Optional[:class:`str`]
562
            audit log reason |default| :data:`None`
563
        Returns
564
        -------
565
        :class:`~pincer.objects.guild.channel.Channel`
566
            The new channel object.
567
        """
568
        ...
569
570
    async def create_channel(self, *, reason: Optional[str] = None, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
571
        data = await self._http.post(
572
            f"guilds/{self.id}/channels",
573
            data=kwargs,
574
            headers={"X-Audit-Log-Reason": reason},
575
        )
576
        return Channel.from_dict(data)
577
578
    async def modify_channel_positions(
0 ignored issues
show
introduced by
Keyword argument before variable positional arguments list in the definition of modify_channel_positions function
Loading history...
579
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
580
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
581
        *channel: Dict[str, Optional[Union[int, bool, Snowflake]]],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
582
    ):
583
        """|coro|
584
        Create a new channel object for the guild.
585
586
        Parameters
587
        ----------
588
        reason : Optional[:class:`str`]
589
            audit log reason |default| :data:`None`
590
        \\*channel : Dict[str, Optional[Union[int, bool, :class:`~pincer.utils.snowflake.Snowflake`]
591
            Keys:
592
                - id : :class:`~pincer.utils.snowflake.Snowflake`
593
                - position : Optional[:class:`int`]
594
                - lock_permissions : Optional[:class:`bool`]
595
                - parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
596
        """
597
        await self._http.patch(
598
            f"guilds/{self.id}/channels",
599
            data=channel,
600
            headers={"X-Audit-Log-Reason": reason},
601
        )
602
603
    async def list_active_threads(
604
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
605
    ) -> Tuple[Generator[Thread], Generator[GuildMember]]:
606
        """|coro|
607
        Returns all active threads in the guild,
608
        including public and private threads.
609
610
        Returns
611
        -------
612
        Generator[Union[:class:`~pincer.objects.guild.channel.PublicThread`, :class:`~pincer.objects.guild.channel.PrivateThread`]], Generator[:class:`~pincer.objects.guild.member.GuildMember`]]
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (194/100).

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

Loading history...
613
            The new member object.
614
        """
615
        data = await self._http.get(f"guilds/{self.id}/threads/active")
616
617
        threads = (Channel.from_dict(channel) for channel in data["threads"])
618
        members = (GuildMember.from_dict(member) for member in data["members"])
619
620
        return threads, members
621
622
    async def list_guild_members(
623
        self, limit: int = 1, after: int = 0
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
624
    ) -> AsyncIterator[GuildMember]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
625
        """|coro|
626
        Returns a list of guild member objects that are members of the guild.
627
628
        Parameters
629
        ----------
630
        limit : int
631
            max number of members to return (1-1000) |default| :data:`1`
632
        after : int
633
            the highest user id in the previous page |default| :data:`0`
634
635
        Yields
636
        ------
637
        :class:`~pincer.objects.guild.member.GuildMember`
638
            the guild member object that is in the guild
639
        """
640
641
        members = await self._http.get(
642
            f"guilds/{self.id}/members", params={"limit": limit, "after": after}
643
        )
644
645
        for member in members:
646
            yield GuildMember.from_dict(member)
647
648
    async def search_guild_members(
649
        self, query: str, limit: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
650
    ) -> AsyncIterator[GuildMember]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
651
        """|coro|
652
        Returns a list of guild member objects whose
653
        username or nickname starts with a provided string.
654
655
        Parameters
656
        ----------
657
        query : str
658
            Query string to match username(s) and nickname(s) against.
659
        limit : Optional[int]
660
            max number of members to return (1-1000) |default| :data:`1`
661
662
        Yields
663
        -------
664
        :class:`~pincer.objects.guild.member.GuildMember`
665
            guild member objects
666
        """
667
668
        data = await self._http.get(
669
            f"guilds/{self.id}/members/search",
670
            params={"query": query, "limit": limit},
671
        )
672
673
        for member in data:
674
            yield GuildMember.from_dict(member)
675
676
    @overload
677
    async def add_guild_member(
678
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
679
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
680
        user_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
681
        access_token: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
682
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
683
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
684
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
685
        deaf: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
686
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
687
    ) -> Optional[GuildMember]:
688
        """|coro|
689
        Adds a user to the guild, provided you have a
690
        valid oauth2 access token for the user with the guilds.join scope.
691
692
        Parameters
693
        ----------
694
        user_id : str
695
            id of the user to be added
696
        access_token : str
697
            an oauth2 access token granted with the guilds.join to
698
            the bot's application for the user you want to add to the guild
699
        nick : Optional[str]
700
            value to set users nickname to
701
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
702
            array of role ids the member is assigned
703
        mute : Optional[bool]
704
            whether the user is muted in voice channels
705
        deaf : Optional[bool]
706
            whether the user is deafened in voice channels
707
        reason : Optional[:class:`str`]
708
            audit log reason |default| :data:`None`
709
        Returns
710
        -------
711
        :class:`~pincer.objects.guild.member.GuildMember`
712
            If the user is not in the guild
713
        None
714
            If the user is in the guild
715
        """
716
717
    async def add_guild_member(self, user_id, reason=None, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
718
        data = await self._http.put(
719
            f"guilds/{self.id}/members/{user_id}",
720
            data=kwargs,
721
            headers={"X-Audit-Log-Reason": reason},
722
        )
723
724
        return GuildMember.from_dict(data) if data else None
725
726
    async def modify_current_member(
727
        self, nick: str, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
728
    ) -> GuildMember:
729
        """|coro|
730
        Modifies the current member in a guild.
731
732
        Parameters
733
        ----------
734
        nick : str
735
            value to set users nickname to
736
        reason : Optional[:class:`str`]
737
            audit log reason |default| :data:`None`
738
        Returns
739
        -------
740
        class:`~pincer.objects.guild.member.GuildMember
741
            current guild member
742
        """
743
        data = self._http.patch(
744
            f"guilds/{self.id}/members/@me",
745
            {"nick": nick},
746
            headers={"X-Audit-Log-Reason": reason},
747
        )
748
        return GuildMember.from_dict(data)
749
750
    async def add_guild_member_role(
751
        self, user_id: int, role_id: int, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
752
    ) -> None:
753
        """|coro|
754
        Adds a role to a guild member.
755
756
        Parameters
757
        ----------
758
        user_id : int
759
            id of the user to give a role to
760
        role_id : int
761
            id of a role
762
        reason : Optional[:class:`str`]
763
            audit log reason |default| :data:`None`
764
        """
765
        data = await self._http.put(
0 ignored issues
show
Unused Code introduced by
The variable data seems to be unused.
Loading history...
766
            f"guilds/{self.id}/{user_id}/roles/{role_id}",
767
            headers={"X-Audit-Log-Reason": reason},
768
        )
769
770
    async def remove_guild_member_role(
771
        self, user_id: int, role_id: int, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
772
    ):
773
        """|coro|
774
        Removes a role from a guild member.
775
776
        Parameters
777
        ----------
778
        user_id : int
779
            id of the user to remove a role from
780
        role_id : int
781
            id of a role
782
        reason : Optional[:class:`str`]
783
            audit log reason |default| :data:`None`
784
        """
785
        await self._http.delete(
786
            f"guilds/{self.id}/{user_id}/roles/{role_id}",
787
            headers={"X-Audit-Log-Reason": reason},
788
        )
789
790
    async def remove_guild_member(
791
        self, user_id: int, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
792
    ):
793
        """|coro|
794
        Remove a member from a guild.
795
796
        Parameters
797
        ----------
798
        user_id : int
799
            id of the user to remove from the guild
800
        reason : Optional[:class:`str`]
801
            audit log reason |default| :data:`None`
802
        """
803
        await self._http.delete(
804
            f"guilds/{self.id}/members/{user_id}",
805
            headers={"X-Audit-Log-Reason": reason},
806
        )
807
808
    async def ban(
809
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
810
        member_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
811
        reason: str = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
812
        delete_message_days: int = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
813
    ):
814
        """
815
        Parameters
816
        ----------
817
        member_id : :class:`int`
818
            ID of the guild member to ban.
819
        reason : Optional[:class:`str`]
820
            Reason for the kick.
821
        delete_message_days : Optional[:class:`int`]
822
            Number of days to delete messages for (0-7)
823
        """
824
        headers = {}
825
826
        if reason is not None:
827
            headers["X-Audit-Log-Reason"] = reason
828
829
        data = {}
830
831
        if delete_message_days is not None:
832
            data["delete_message_days"] = delete_message_days
833
834
        await self._http.put(
835
            f"/guilds/{self.id}/bans/{member_id}", data=data, headers=headers
836
        )
837
838
    async def kick(self, member_id: int, reason: Optional[str] = None):
839
        """|coro|
840
        Kicks a guild member.
841
        Parameters
842
        ----------
843
        member_id : :class:`int`
844
            ID of the guild member to kick.
845
        reason : Optional[:class:`str`]
846
            Reason for the kick.
847
        """
848
849
        headers = {}
850
851
        if reason is not None:
852
            headers["X-Audit-Log-Reason"] = reason
853
854
        await self._http.delete(
855
            f"/guilds/{self.id}/members/{member_id}", headers=headers
856
        )
857
858
    async def get_roles(self) -> AsyncGenerator[Role, None]:
859
        """|coro|
860
        Fetches all the roles in the guild.
861
862
        Yields
863
        -------
864
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
865
            An async generator of Role objects.
866
        """
867
        data = await self._http.get(f"guilds/{self.id}/roles")
868
        for role_data in data:
869
            yield Role.from_dict(role_data)
870
871
    @overload
872
    async def create_role(
873
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
874
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
875
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
876
        name: Optional[str] = "new role",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
877
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
878
        color: Optional[int] = 0,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
879
        hoist: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
880
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
881
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
882
        mentionable: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
883
    ) -> Role:
884
        """|coro|
885
        Creates a new role for the guild.
886
        Requires the ``MANAGE_ROLES`` permission.
887
888
        Parameters
889
        ----------
890
        reason : Optional[:class:`str`]
891
            Reason for creating the role. |default| :data:`None`
892
        name : Optional[:class:`str`]
893
            name of the role |default| :data:`"new role"`
894
        permissions : Optional[:class:`str`]
895
            bitwise value of the enabled/disabled
896
            permissions, set to @everyone permissions
897
            by default |default| :data:`None`
898
        color : Optional[:class:`int`]
899
            RGB color value |default| :data:`0`
900
        hoist : Optional[:class:`bool`]
901
            whether the role should be displayed
902
            separately in the sidebar |default| :data:`False`
903
        icon : Optional[:class:`str`]
904
            the role's icon image (if the guild has
905
            the ``ROLE_ICONS`` feature) |default| :data:`None`
906
        unicode_emoji : Optional[:class:`str`]
907
            the role's unicode emoji as a standard emoji (if the guild
908
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
909
        mentionable : Optional[:class:`bool`]
910
            whether the role should be mentionable |default| :data:`False`
911
912
        Returns
913
        -------
914
        :class:`~pincer.objects.guild.role.Role`
915
            The new role object.
916
        """
917
        ...
918
919
    async def create_role(self, reason: Optional[str] = None, **kwargs) -> Role:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
920
        return Role.from_dict(
921
            await self._http.post(
922
                f"guilds/{self.id}/roles",
923
                data=kwargs,
924
                headers={"X-Audit-Log-Reason": reason},
925
            )
926
        )
927
928
    async def edit_role_position(
929
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
930
        id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
931
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
932
        position: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
933
    ) -> AsyncGenerator[Role, None]:
934
        """|coro|
935
        Edits the position of a role.
936
937
        Parameters
938
        ----------
939
        id : :class:`~pincer.utils.snowflake.Snowflake`
940
            The role ID
941
        reason : Optional[:class:`str`]
942
            Reason for editing the role position. |default| :data:`None`
943
        position : Optional[:class:`int`]
944
            Sorting position of the role |default| :data:`None`
945
946
        Yields
947
        -------
948
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
949
            An async generator of all the guild's role objects.
950
        """
951
        data = await self._http.patch(
952
            f"guilds/{self.id}/roles",
953
            data={"id": id, "position": position},
954
            headers={"X-Audit-Log-Reason": reason},
955
        )
956
        for role_data in data:
957
            yield Role.from_dict(role_data)
958
959
    @overload
960
    async def edit_role(
961
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
962
        id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
963
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
964
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
965
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
966
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
967
        color: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
968
        hoist: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
969
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
970
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
971
        mentionable: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
972
    ) -> Role:
973
        """|coro|
974
        Edits a role.
975
        Requires the ``MANAGE_ROLES`` permission.
976
977
        Parameters
978
        ----------
979
        id : :class:`~pincer.utils.snowflake.Snowflake`
980
            The role ID
981
        reason : Optional[:class:`str`]
982
            Reason for editing the role |default| :data:`None`
983
        name : Optional[:class:`str`]
984
            Name of the role |default| :data:`None`
985
        permissions : Optional[:class:`str`]
986
            Bitwise value of the enabled/disabled
987
            permissions |default| :data:`None`
988
        color : Optional[:class:`int`]
989
            RGB color value |default| :data:`None`
990
        hoist : Optional[:class:`bool`]
991
            Whether the role should be displayed
992
            separately in the sidebar |default| :data:`None`
993
        icon : Optional[:class:`str`]
994
            The role's icon image (if the guild has
995
            the ``ROLE_ICONS`` feature) |default| :data:`None`
996
        unicode_emoji : Optional[:class:`str`]
997
            The role's unicode emoji as a standard emoji (if the guild
998
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
999
        mentionable : Optional[:class:`bool`]
1000
            Whether the role should be mentionable |default| :data:`None`
1001
1002
        Returns
1003
        -------
1004
        :class:`~pincer.objects.guild.role.Role`
1005
            The edited role object.
1006
        """
1007
        ...
1008
1009
    async def edit_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
1010
        self, id: Snowflake, reason: Optional[str] = None, **kwargs
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1011
    ) -> Role:
1012
        return Role.from_dict(
1013
            await self._http.patch(
1014
                f"guilds/{self.id}/roles/{id}",
1015
                data=kwargs,
1016
                headers={"X-Audit-Log-Reason": reason},
1017
            )
1018
        )
1019
1020
    async def delete_role(self, id: Snowflake, reason: Optional[str] = None):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
1021
        """|coro|
1022
        Deletes a role.
1023
        Requires the `MANAGE_ROLES` permission.
1024
1025
        Parameters
1026
        ----------
1027
        id : :class:`~pincer.utils.snowflake.Snowflake`
1028
            The role ID
1029
        reason : Optional[:class:`str`]
1030
            The reason for deleting the role |default| :data:`None`
1031
        """
1032
        await self._http.delete(
1033
            f"guilds/{self.id}/roles/{id}",
1034
            headers={"X-Audit-Log-Reason": reason},
1035
        )
1036
1037
    async def get_bans(self) -> AsyncGenerator[Ban, None]:
1038
        """|coro|
1039
        Fetches all the bans in the guild.
1040
1041
        Yields
1042
        -------
1043
        AsyncGenerator[:class:`~pincer.objects.guild.ban.Ban`, :data:`None`]
1044
            An async generator of Ban objects.
1045
        """
1046
        data = await self._http.get(f"guilds/{self.id}/bans")
1047
        for ban_data in data:
1048
            yield Ban.from_dict(ban_data)
1049
1050
    async def get_ban(self, id: Snowflake) -> Ban:
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

Loading history...
1051
        """|coro|
1052
        Fetches a ban from the guild.
1053
1054
        Parameters
1055
        ----------
1056
        id : :class:`~pincer.utils.snowflake.Snowflake`
1057
            The user ID
1058
1059
        Returns
1060
        -------
1061
        :class:`~pincer.objects.guild.ban.Ban`
1062
            The Ban object.
1063
        """
1064
        return Ban.from_dict(
1065
            await self._http.get(f"guilds/{self.id}/bans/{id}")
1066
        )
1067
1068
    async def unban(self, id: Snowflake, reason: Optional[str] = None):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

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

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

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

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